Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我使用表视图时,我的iphone应用程序崩溃_Iphone_Xcode - Fatal编程技术网

当我使用表视图时,我的iphone应用程序崩溃

当我使用表视图时,我的iphone应用程序崩溃,iphone,xcode,Iphone,Xcode,文件values.plist中插入了三个值,它们填充函数viewDidLoad()中的NSArray“table”,但我的应用程序在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *theCell=[UITableViewCell alloc]; theCell=[theCell in

文件values.plist中插入了三个值,它们填充函数viewDidLoad()中的NSArray“table”,但我的应用程序在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *theCell=[UITableViewCell alloc];
     theCell=[theCell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

      NSLog(@"%i",[table count]);

         theCell.textLabel.text=[table objectAtIndex:[indexPath row]];  

    return theCell;
}

请注意以下问题:

1) 确保NSArray具有值,即它已填充

2) 还可以尝试
NSLog(@“%d”,[table count])

我认为你最好选择
%d
,而不是
%I


希望这对您有所帮助。

这是标准实现:

" theCell.textLabel.text=[table objectAtIndex:[indexPath row]];  "
But the line "NSLog(@"%i",[table count]);" works and shows me 3
please help .
作为旁注,这是ARC实现。如果您不使用ARC,只需添加自动释放:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }


       cell.textLabel.text = [table objectAtIndex:indexPath.row];
        return cell;
    }
还要确保数据源numberOfSections设置正确:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autoRelease];
并将numberOfRows设置为数组:

return 1;

发布应用程序崩溃时收到的错误消息会有所帮助。在控制台中查看以找到它。堆栈跟踪也很有用。那么错误消息是什么呢??确保数组中有字符串值。
return [table count];