刷新 UITableView 在第三个单元格后崩溃后滚动到顶部 [英] Scroll to top after refreshing UITableView crashes after third cell
本文介绍了刷新 UITableView 在第三个单元格后崩溃后滚动到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的刷新方法中,我使用以下代码滚动到顶部,这工作正常,但是当我在第三个单元格之后向下滚动并再次点击刷新时,应用程序崩溃,错误终止,未捕获异常输入 NSException
.
In my refresh method I'm using the following code to scroll to top which is working fine, but when I scroll down after the third cell and hit refresh again it crashes the app with error terminating with uncaught exception of type NSException
.
[TableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
UITableView
有 7 个动态单元格.我是否需要添加一些东西以使其适用于整个 tableview?
The UITableView
has 7 dynamic cells. Do I need to add something to make it work for the whole tableview?
我在 StackOverflow 上搜索了一个解决方案,但不幸的是没有一个解决了我的问题.
I searched on StackOverflow for a solution, but none of them solved my problem unfortunately.
推荐答案
给你...
- (void)viewDidLoad
{
[super viewDidLoad];
NewsTbView.delegate = self;
NewsTbView.dataSource = self;
[self refresh];
}
-(void)refresh
{
catName = @"All";
self.imageArray = [[NSMutableArray alloc]init];
self.titleArray = [[NSMutableArray alloc]init];
self.descArray = [[NSMutableArray alloc]init];
self.dateArray = [[NSMutableArray alloc]init];
self.linkArray = [[NSMutableArray alloc]init];
self.categoryArray = [[NSMutableArray alloc]init];
self.categoryNewsArray = [[NSMutableArray alloc]init];
self.imageCatArray = [[NSMutableArray alloc]init];
self.titleCatArray = [[NSMutableArray alloc]init];
self.descCatArray = [[NSMutableArray alloc]init];
self.dateCatArray = [[NSMutableArray alloc]init];
self.linkCatArray = [[NSMutableArray alloc]init];
// Create the request.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[config getXmlWordPress]]];
// Create url connection and fire request
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Verversen";
hud.dimBackground = YES;
[NewsTbView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIndent";
TableViewCellHome *cell = (TableViewCellHome *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *CellName;
CellName = @"TableViewCellHome";
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:CellName bundle:nil];
cell = (TableViewCellHome *)c.view;
}
cell.textLabel.numberOfLines = 0;
[cell.txtDate setAlpha:0];
[cell.txtTitle setAlpha:0];
[cell.btnShare setAlpha:0];
[cell.imgNews setAlpha:0];
[UIView beginAnimations:@"CustomCellAnimation" context:NULL];
[UIView setAnimationDuration:1.0f];
[cell.txtDate setAlpha:1];
[cell.txtTitle setAlpha:1];
//[cell.btnShare setAlpha:1];
[cell.imgNews setAlpha:1];
[UIView commitAnimations];
if ([catName isEqualToString:@"All"]) {
cell.txtTitle.text = [titleArray objectAtIndex:indexPath.row];
cell.txtDate.text = [dateArray objectAtIndex:indexPath.row];
[cell.imgNews setImage:[imageArray objectAtIndex:indexPath.row]];
[cell.btnShare addTarget:self
action:@selector(sharePost:)
forControlEvents:UIControlEventTouchUpInside];
cell.btnShare.tag = indexPath.row;
}
else
{
cell.txtTitle.text = [titleCatArray objectAtIndex:indexPath.row];
cell.txtDate.text = [dateCatArray objectAtIndex:indexPath.row];
[cell.imgNews setImage:[imageCatArray objectAtIndex:indexPath.row]];
[cell.btnShare addTarget:self
action:@selector(sharePost:)
forControlEvents:UIControlEventTouchUpInside];
cell.btnShare.tag = indexPath.row;
}
return cell;
}
这篇关于刷新 UITableView 在第三个单元格后崩溃后滚动到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文