2014-03-04 48 views
0

我試圖在用戶按下鍵盤上的返回後插入一行。 的textFieldShouldReturn方法中的代碼看起來是這樣的:insertRowsAtIndexPaths插入行a

NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:([self.tableView numberOfRowsInSection:([self.tableView numberOfSections] - 1)] - 1) 
               inSection:([self.tableView numberOfSections] - 1)]; 

[self.tableView insertRowsAtIndexPaths:@[lastIndexPath] 
         withRowAnimation:UITableViewRowAnimationRight]; 

這直到10行被示出,在這之後,行被插入在開始正常工作,然後一個和所述的tableView的結束。 我該如何解決這個問題?

+0

檢查lastIndexPath的值...? – CW0007007

+0

lastIndexPath的值是正確的。 – joelfischerr

回答

3

我很確定你沒有更新你的數據。兩種方法之一

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

of UITableViewDataSource返回錯誤的數據。

UITableView只顯示數據。你應該把它存儲在某個地方。

+0

謝謝,它只是奇怪,它首先工作,然後停止正常工作。 – joelfischerr

+0

numberOfRowsInSection返回的數據是正確的。 – joelfischerr

+0

@sixbeat,你可以添加額外的代碼到你的問題或打開另一個。現在還沒有足夠的信息來說出還有什麼可能是錯的。 – Avt