我有一个关于 UIActivity Indicator 的问题,我正在 UITableView Cell 上实现 Activity 指示器,但它不起作用。我的代码如下,如果可以解决,请告诉我我在其中做的错误。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIActivityIndicatorView *indicator=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
if (segmentControl.selectedSegmentIndex==0)
{
if ([indexPath row]==[FriendSuggestion count])
{
int cursor=[Constants getCursorForKey:@"friendList_cursor"];
if (cursor!=0)
{
[[tableView cellForRowAtIndexPath:indexPath] addSubview:indicator];
[indicator setFrame:CGRectMake(40, 25, 37, 37)];
[NSThread detachNewThreadSelector:@selector(startAnimating) toTarget:indicator withObject:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self loadingMore:indexPath :indicator :cursor];
});
}else
isNoMoreData=YES;
[tableView reloadData];
}
}
else
{
if ([indexPath row]==[popularSuggestion count])
{
int cursor=[Constants getCursorForKey:@"popularList_cursor"];
if (cursor!=0)
{
[[tableView cellForRowAtIndexPath:indexPath] addSubview:indicator];
[indicator setFrame:CGRectMake(40, 25, 37, 37)];
[NSThread detachNewThreadSelector:@selector(startAnimating) toTarget:indicator withObject:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self loadingMore:indexPath :indicator :cursor];
});
}else
isNoMoreData=YES;
[tableView reloadData];
}
}
}
-(void)loadingMore:(NSIndexPath*)indexPath:(UIActivityIndicatorView*)indicator:(int)cursor
{
NSLog(@"loading more called ...");
if (segmentControl.selectedSegmentIndex==0)
{
isNoMoreData=NO;
NSArray *nextArray=[[NSArray alloc] init];
nextArray=[Constants getFriendsSuggestionsStr:cursor];
for (NSDictionary *dic in nextArray) {
[FriendSuggestion addObject:dic];
}
}else
{
isNoMoreData=NO;
NSArray *nextArray=[[NSArray alloc] init];
nextArray=[Constants getPopularSuggestionsStr:cursor];
for (NSDictionary *dic in nextArray) {
[popularSuggestion addObject:dic];
}
}
[table reloadData];
[indicator stopAnimating];
}
提前致谢..!