Xcode数组到TableView

时间:2011-09-30 04:00:26

标签: arrays xcode tableview

我正在制作一个有按钮的简单应用程序。单击时,它将移动到另一个ViewController。当我加载带有表视图的新ViewController时,我访问输出字符串的服务器,该字符串放入数组中。在did load函数中,Array已成功读取。当我将数组放置在由表函数处理时,BUt会关闭..

这是我的代码..

- (UITableViewCell *)tableView:(UITableView *)tableView 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帮帮我!!我真的很困惑.. ^^ ,,谢谢!顺便说一句,我使用Xcode 3.2.6与iOS SDK 4.x

0 个答案:

没有答案