2013-10-02 2 views
0

나는 해결책을 찾을 수없는 문제에 빠지기 때문에 누군가가 나를 도와 줄 수 있다면 그것을 고맙게 생각할 것입니다. 문제가 될 수있는 게시물을 많이 읽었지만 해결책을 찾지 못했습니다. 가 나는 .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; 

} 
+0

numberOfRowsInSection : 0 또는 nil이 반환됩니다. –

+0

전화가 걸리지 않는 것을 어떻게 알 수 있습니까? 복사 및 붙여 넣기입니까? cellForRow에 'CellIdentifier'를 선언하지 않았습니다. – Justin

+0

NSArray * jsonArray = [firstJsonData objectForKey : @ "data"]; NSInteger numberOfRows = [jsonArray count]; NSLog (@ "Count : % i", numberOfRows); return numberOfRows; –

답변

1

바르를 선언하지 마십시오 UITableView *myTableView

@synthesize myTableView

항상 위의 코드 self.myTableView

3

첫째가, 코드는 잘 실행해야합니다.

  • numberOfRowsInSection 함수가 유효한 숫자를 반환해야합니다.
  • "myTableView"가 nil이 아니어야합니다.

  • "myTableView"가 배경색 노란색으로 표시되어 있는지 확인하십시오.

+0

@ 메 메트, 나는 그것이 잘 실행 해야하는지 알고, 나는 체크하고 작성 'numberOfRowsInSection'에 대한 요점 나는 또한 다음 두 점이 우스꽝 스럽기 때문에 노란색 collor에 관해 썼다. 잊어 버린 IBOutlet이 있었고 실제로 테이블에 다시로드됩니다. – Spire

+1

이 덕분에 도움이되었는데, 나는 분명히 나를 위해 문제가되었던 섹션의 행 수를 보지 못했다. – StuartM

1
-(void)viewWillAppear:(BOOL)animated{ 

    [self performSelector:@selector(reloadTable) withObject:nil afterDelay:0.2]; 

    [self.tableView reloadData]; not working 

} 

- (void)reloadTable { 

    [self.tableView reloadData]; 
} 

이 선택 방법에 테이블을 다시로드 나를 위해 작동하는 속성 접근을 통해 myTableView에 액세스하지 마십시오 .

관련 문제