Xcode Array to TableView
I was making a simple application that has a button. When clicked, it moves to another ViewController
. As I load the new ViewController
with a table view in it, I access the server that outputs a string that I place into an array. In the did load function, the Array was successfully read. BUt when I place the array to be processed by the table functions, the program shuts down..
here is my code..
- (UITableViewCell *)tableView:(UITableView *)tableView开发者_如何学JAVA cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *psalmCell = [tableView dequeueReusableCellWithIdentifier:@"psalmcell"];
//create a cell
if(psalmCell == nil)
{
psalmCell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"psalmcell"];
}
//fill contents
psalmCell.textLabel.text = @"Psalm";
psalmCell.textLabel.text = [listItemsR objectAtIndex:indexPath.row];
//return
return psalmCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return listItemsR.count;
}
- (void)viewDidLoad {
NSURL *url = [NSURL URLWithString:@"http://sample.stie.com/sample.php"];
NSString *response_string = @"";
//
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"retrievePending" forKey:@"command"];
[request startSynchronous];
response_string = [request responseString];
NSLog(@"JSON : %@",response_string);
listItemsR = [[NSArray alloc] initWithArray:listItemsR];
listItemsR = [response_string componentsSeparatedByString:@":"];
NSInteger arCount = listItemsR.count;
NSLog(@"%d",arCount);
for(NSInteger i=1; i<arCount; i++){
NSString *final = [listItemsR objectAtIndex:i];
NSLog(@"%@",final);
}
[listItemsR release];
}
PLease do help me!! Im really confused here.. ^^,, Thanks!!! By the way Im using Xcode 3.2.6 with iOS SDK 4.x
精彩评论