나는 해결책을 찾을 수없는 문제에 빠지기 때문에 누군가가 나를 도와 줄 수 있다면 그것을 고맙게 생각할 것입니다. 문제가 될 수있는 게시물을 많이 읽었지만 해결책을 찾지 못했습니다. 가 나는 .HreloadData는 cellForRowAtIndexPath를 호출하지 않습니다.
@interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
UITableView *myTableView;
}
@property (strong, nonatomic) UITableView *myTableView;
@end
하고하는 .m 모두의
@interface FirstViewController()
@end
@implementation FirstViewController
@synthesize myTableView;
static NSString *CellIdentifier = @"CellIdentifier";
- (void)viewDidLoad
{
[super viewDidLoad];
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
myTableView.dataSource = self;
myTableView.delegate = self;
[self.view addSubview:myTableView];
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
myTableView.rowHeight = 325;
myTableView.backgroundColor = [UIColor yellowColor];
[myTableView setDelegate:self];
[myTableView setDataSource:self];
[myTableView registerClass:[MTTableViewCell class] forCellReuseIdentifier:CellIdentifier];
[self separateByType];
}
-(void)separateByType
{
NSURL *url = [NSURL URLWithString:tempUrl];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *response = [request responseString];
SBJsonParser *jsonReader = [SBJsonParser new];
firstJsonData = [NSMutableDictionary dictionary];
firstJsonData = [jsonReader objectWithString:response error:nil];
NSLog(@"Calling reloadData on %@", self.myTableView);
[self.myTableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[firstJsonData objectForKey:@"data"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MTTableViewCell *cell = (MTTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[MTTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.titleTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
[cell.descriptionTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
return cell;
}
numberOfRowsInSection : 0 또는 nil이 반환됩니다. –
전화가 걸리지 않는 것을 어떻게 알 수 있습니까? 복사 및 붙여 넣기입니까? cellForRow에 'CellIdentifier'를 선언하지 않았습니다. – Justin
NSArray * jsonArray = [firstJsonData objectForKey : @ "data"]; NSInteger numberOfRows = [jsonArray count]; NSLog (@ "Count : % i", numberOfRows); return numberOfRows; –