Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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应用程序中加载UITableView?_Iphone_Uitableview_Loading_Tabbar - Fatal编程技术网

在基于选项卡的iPhone应用程序中加载UITableView?

在基于选项卡的iPhone应用程序中加载UITableView?,iphone,uitableview,loading,tabbar,Iphone,Uitableview,Loading,Tabbar,在UITabBarController上加载UITableView时出现问题,在使用tab加载表格时出现此错误 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView数据源必须从tableView返回单元格:CellForRowatineXpath:” 我的密码在这里 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Retur

在UITabBarController上加载UITableView时出现问题,在使用tab加载表格时出现此错误

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView数据源必须从tableView返回单元格:CellForRowatineXpath:”

我的密码在这里

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

return cell;
}

我试了很多,可能很简单。。有人请帮助我吗?

问题是您正在使用
dequeueReusableCellWithIdentifier
,但如果返回nil(即,尚未创建要重复使用的单元格),则没有代码可处理

例如:

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

您忘记了检查条件
如果(cell==nil)
而无需创建新的
单元格,则它将重新使用。谢谢您的重播,是的,我忘记了检查条件。谢谢,现在它可以正常工作了。@NeerajNeeru,gr8 happie coding!:)
//Editing in your code, it should work.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 2;
}

- (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];
    }

    return cell;
}