Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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
Ios UITableView未重新加载_Ios_Objective C_Cocoa Touch_Cocoa - Fatal编程技术网

Ios UITableView未重新加载

Ios UITableView未重新加载,ios,objective-c,cocoa-touch,cocoa,Ios,Objective C,Cocoa Touch,Cocoa,我正在制作一个使用UITableView和UITableView控制器的应用程序。但是,当我调用[self.tableView reloadData]在UITableViewController中,什么也不发生(tableView:cellforrowatinexpath:未被调用)。我该怎么办 - (void) UserChangedAmmountAndCurrency: (NSNotification*) notification { self.localBank.activeAmm

我正在制作一个使用
UITableView
UITableView控制器的应用程序。但是,当我调用
[self.tableView reloadData]
UITableViewController
中,什么也不发生(
tableView:cellforrowatinexpath:
未被调用)。我该怎么办

- (void) UserChangedAmmountAndCurrency: (NSNotification*) notification {
    self.localBank.activeAmmount=((NSNumber*)[notification.userInfo objectForKey:@"newAmmount"]).doubleValue;
    self.localBank.activeCurrency=[self.localBank.worldBank requestCurrencyForLocalBank:((NSString*)[notification.userInfo objectForKey:@"newISO4217Currency"])];
    [self.tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSNumber *ammount= [self.localBank ammountForElementAtIndex:indexPath.row];
    VIPCurrency* currency=[self.localBank currencyForElementAtIndex:indexPath.row];


    static NSString *CellIdentifier = @"cellWithCurrencyAndAmmount";
    VIPConversionCell* cell=[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.longCurencyIdentifier.text=currency.longName;
    cell.shortCurrencyIdentifier.text=currency.shortName;
    cell.textfieldForAmmount.text=ammount.stringValue;
    return cell;
}
编辑: 我做了一些额外的测试。我测试了tableview数据源和委托是我用来调用重载方法的viewcontroller,这是正常的。我也注意到了一些奇怪的事情。调用reloadData时,既不调用
numberOfSectionsInTableView:
也不调用
numberOfRowsInSection:
。我觉得在调用reloadData之前我没有做一件基本的事情,但我不知道是什么。是否我必须以某种方式特别设置单元格为过期


编辑:我还检查了该方法是否在主线程中被调用,这也可以

dequeReusableCellWithIdentifier
调用中检查
nil
的想法是创建一个新单元格并返回它。除非您之前使用给定标识符创建了一个单元格,并且该单元格位于可重用池中,否则该方法将返回
nil
。因此,正如@Verec所提到的,您应该检查
nil
,自己创建单元格,然后
返回您只需要添加的

UITableViewDataSource,UITableViewDelegate
in.h

范例

@interface yourviewcontroller : UIViewController <UITableViewDataSource,UITableViewDelegate>
@界面yourviewcontroller:UIViewController

.xib
文件和
.h
文件
(UITableViewDataSource,UITableViewDelegate)中设置表视图委托


[myTableView重新加载数据]

当dequeueReusableCellWithIdentifier返回nil时,您的代码无法处理这种情况……我打赌您没有将tableView:CellForRowatineXpath:的实现者设置为表视图的数据源。或者您没有指定tableView属性。尝试记录self.tableView。是nil吗?当我使用故事板创建表视图时,是否应该为表视图设置委托和数据源?而且,第一次数据加载很好,但当我更改模型并要求tableview重新加载时,它不会调用数据源cellFor…-方法。有什么问题吗?Verec,当dequeueReusableCellWithIdentifier返回nill时,是否有理由我想从这个方法返回nill以外的东西?我想如果是这样的话,肯定会有一个bug。在这里处理hill的案例有什么不同的理念吗?我已经使用Log函数进行了明确的检查,视图的数据源设置正确,视图本身非常活跃…:(我在故事板中创建了带有标识符的单元作为原型单元,因此当队列为空时将创建并提供一个新单元。不,您不再需要检查nil。根据苹果公司的说法,您应该使用dequeueReusableCellWithIdentifier:forIndexPath:而不是dequeueReusableCellWithIdentifier:,但我注意到t似乎无关紧要。只要你在故事板中创建了你的单元格,并且你有正确的标识符,它就应该可以工作。此外,OP说第一次加载的表很好。如果你已经使用可重用标识符注册了一个
nib
,在iOS5+中,
UITableView
会自动为你创建一个有效的单元格如果队列中没有可重用的单元格;因此指针永远不会是
nil
,您不需要处理它。仅声明符合协议不会产生任何影响;这只意味着控制器可以是表视图数据源/委托。提问者还必须将此控制器设置为数据源并删除有关表视图的e。