Cant bind data to a table view
Posted
by sudhakarilla
on Stack Overflow
See other posts from Stack Overflow
or by sudhakarilla
Published on 2010-06-11T14:30:10Z
Indexed on
2010/06/11
14:32 UTC
Read the original article
Hit count: 284
iphone
|iphone-sdk
Hi,
I have retrieved data from Json URL and displayed it in a table view. I have also inlcuced a button in table view. On clicking the button the data must be transferred to a another table view. The problem is that i could send the data to a view and could display it on a label. But i couldnt bind the dat to table view ... Here's some of the code snippets...
Buy Button...
-(IBAction)Buybutton{
/*
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"thank u"
message:@"products"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
[alert release];*/
Product *selectedProduct = [[data products]objectAtIndex:0];
CartViewController *cartviewcontroller = [[[CartViewController alloc] initWithNibName:@"CartViewController" bundle:nil]autorelease];
cartviewcontroller.product= selectedProduct;
//NSString *productname=[product ProductName];
//[currentproducts setproduct:productname];
[self.view addSubview:cartviewcontroller.view];
}
CartView...
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad { [super viewDidLoad];
data = [GlobalData SharedData];
NSMutableArray *prod =[[NSMutableArray alloc]init];
prod = [data products];
for(NSDictionary *product in prod)
{
Cart *myprod = [[Cart alloc]init];
myprod.Description = [product Description];
myprod.ProductImage =[product ProductImage];
myprod.ProductName = [product ProductName];
myprod.SalePrice = [product SalePrice];
[data.carts addObject:myprod];
[myprod release];
}
Cart *cart = [[data carts]objectAtIndex:0];
NSString *productname=[cart ProductName];
self.label.text =productname;
NSLog(@"carts");
}
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [data.carts count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 75; }
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"cellforrow"); static NSString *CellIdentifier = @"Cell";
ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell ==nil) { cell = [[[ProductCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease]; } NSUInteger row = [indexPath row]; Cart *cart = [[data carts]objectAtIndex:row]; cell.productNameLabel.text = [cart ProductName];
/*NSString *sale = [[NSString alloc]initWithFormat:@"SalePrice:%@",[cart SalePrice]];
cell.salePriceLabel.text = sale;
cell.DescriptionLabel.text = [cart Description];
NSMutableString imageUrl =[NSMutableString string]; [imageUrl appendFormat:@"http://demo.s2commerce.net/DesktopModules/S2Commerce/Images/Products/%@",[product ProductImage]];
NSLog(@"imageurl:%@",imageUrl); NSString mapURL = [imageUrl stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* image = [[UIImage alloc]initWithData:imageData]; cell.productImageview.image = image; [imageData release]; [image release];*/
return cell;
}
I am also getting the following error in the console
2010-06-11 18:34:29.169 navigation[4109:207] * -[CartViewController tableView:numberOfRowsInSection:]: message sent to deallocated instance 0xcb4d4f90
© Stack Overflow or respective owner