Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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/7/wcf/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 填充一个tableView&x27;t更新_Iphone_Ios_Xcode_Ipad - Fatal编程技术网

Iphone 填充一个tableView&x27;t更新

Iphone 填充一个tableView&x27;t更新,iphone,ios,xcode,ipad,Iphone,Ios,Xcode,Ipad,这是我的问题。我有一个根据数组内容填充的表视图。到目前为止,一切都很好。此数组用于存储来自服务器的一些映射名称。我有一个刷新按钮,当我点击它时,它将用新的映射名称(refreshmethod)更新数组 当我单击“刷新”按钮时,贴图数组被修改。添加或删除某些地图(例如,如果用户删除了地图或创建了新地图)。但是,这种情况不会反映在屏幕上 假设我有5张地图(命名为1,2,3,4,5)。如果我删除一个(比如Map3)并调用refresh,则maps数组(mapsModel->mapsNameList)将

这是我的问题。我有一个根据数组内容填充的表视图。到目前为止,一切都很好。此数组用于存储来自服务器的一些映射名称。我有一个刷新按钮,当我点击它时,它将用新的映射名称(
refresh
method)更新数组

当我单击“刷新”按钮时,贴图数组被修改。添加或删除某些地图(例如,如果用户删除了地图或创建了新地图)。但是,这种情况不会反映在屏幕上

假设我有5张地图(命名为1,2,3,4,5)。如果我删除一个(比如Map3)并调用refresh,则maps数组(
mapsModel->mapsNameList
)将包含4个贴图,并且该数组的内容是正确的。然而,在iphone屏幕上,我会在表格视图中看到,(1,2,4,5,5)。我不知道如果一行不再在maps数组中,它为什么不删除它

如果我尝试添加一个映射(比如一个映射0),我会得到(0,1,2,3,4),而数字5将不存在

如果重新启动应用程序,则所有地图都会正确显示…

这是我的代码,如果一些变量的名字不明显,请让我知道

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int numberOfRows = [[MapsModel sharedMapsModel] numberOfMapsInSection:((UITabBarController*) self.parentViewController).tabBar.selectedItem.tag];

    // Return the number of rows in the section. THIS FUNCTION WORKS
    return numberOfRows;
}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [[cell textLabel] setText:[[mapsModel->mapsNameList objectAtIndex:((UITabBarController*) self.parentViewController).tabBar.selectedItem.tag] objectAtIndex:indexPath.row]];

    return cell;
}


-(void) refresh {
   [[MapsModel sharedMapsModel] populateMapsNameListWithMapState:MAP_STATE_ALL];

    [self updateView];
}

-(void) updateView {
    //Reorder the maps by alphabetical order
    NSSortDescriptor *sortDescriptor;
    MapsModel* mapsModel = [MapsModel sharedMapsModel];

    sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];

    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    [[mapsModel->mapsNameList objectAtIndex:self.tabBarItem.tag] sortUsingDescriptors:sortDescriptors];

    //Update the table view
    [self.tableView reloadData];
}

您确定更新后
[[MapsModel sharedMapsModel]numberOfMapsInSection:
返回正确的值吗?您的表代码没有问题,似乎您应该检查
MapsModel

可能您的mapsModel在
单元格中返回了错误的值,如RowAtIndexPath:
行数部分:

我知道问题所在,我有一个选项卡栏控制器和三个表视图。但是,我尝试对所有三个表视图只使用一个视图控制器…每个表视图一个视图控制器解决了我的问题!

您知道吗意思是更新后,您在
-(NSInteger)tableView:(UITableView*)tableView numberofrowsinssection:(NSInteger)节中返回4,但您的表有5行?准确地说。numberOfRows将包含4行(删除一行后)但该表将有5行。基本上,该表将保留它提供的第一行数。我想我知道问题所在,我有一个选项卡栏控制器,我想我只有一个用于三个表视图的tableViewController…请仅在尝试某些内容后发布问题。如果选项卡之间的唯一区别是内容对于表视图,您可以在其中为所有视图使用一个视图控制器和一个表视图,在选项卡之间切换时仅更改数据源并重新加载表。它应该可以工作,每个视图控制器和表视图不需要一个视图控制器和一个表视图tab@MilKyWaY我试了5个小时才发布这个问题。我不认为它只是这么简单这就解决了我的问题!请不要太苛刻,这里的人都在努力学习。@AbbasMousavi这是最奇怪的事情,我在三个不同的视图控制器中编写了相同的代码,现在它正在工作。。。。