테이블 뷰의 배열 속성에 일부 데이터를 저장하는 API 호출이 있습니다.cellForRowAtIndexPath 다음에 ViewDidLoad 성공 블록이 호출되었습니다.
나는 viewDidLoad
으로 전화를 걸며, 성공하기 전에 API 호출을 실행하는 것을 제외하고는 모두 잘 돌아 간다.
다음 cellForRowAtIndexPath
으로 이동하여 NSDictionary
에 대한 호출에서 얻은 데이터를 설정하고 해당 행 다음에 cellForRowAtIndexPath
메서드를 완료하지 않습니다. 그것은 다시 점프와 cellForRowAtIndexPath
이 직접 성공 블록 전에 하나의 viewDidLoad에서이다 얻을 라인에 다시 재개하기 전에 API 호출의 성공 코드를 실행합니다 :
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
그 다음 cellForRowAtIndexPath이 라인에 점프 :
0
의 viewDidLoad 방법 :
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.tableFooterView = [[UIView alloc] init];
GFCredentialStore *credentialStore = [[GFCredentialStore alloc] init];
NSString *authToken = [credentialStore authToken];
NSLog(@"%@", authToken);
__weak typeof(self)weakSelf = self;
NSString *userID = self.userID;
NSString *urlString = [NSString stringWithFormat:@"%s%s%@%@", kBaseURL, kUserURL, userID, @".json"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [GFUserResponseSerializer serializer];
[manager.requestSerializer setValue:authToken forHTTPHeaderField:@"auth_token"];
NSLog(@"%@", manager.requestSerializer.HTTPRequestHeaders);
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
__strong typeof(weakSelf)strongSelf = weakSelf;
strongSelf.user = (NSArray *)responseObject;
[strongSelf.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
cellForRowAtIndexPath 방법 : 어떤 도움
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0){
GFProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"profileCell" forIndexPath:indexPath];
NSDictionary *user = self.user[0];
cell.usernameLabel.text = user[@"username"];
cell.bioLabel.text = user[@"description"];
NSString * avatarURL = [NSString stringWithFormat:@"%s%s%@%s%@%s", kBaseURL, "system/users/avatars/", user[@"id"], "/original/", user[@"username"], ".png"];
NSString * newAvatarURL = [avatarURL stringByReplacingOccurrencesOfString:@" " withString:@"_"];
[cell.avatarImage setImageWithURL:[NSURL URLWithString:newAvatarURL] placeholderImage:[UIImage imageNamed:@"Zoo.png"]];
cell.avatarImage.layer.cornerRadius = 40;
cell.avatarImage.layer.masksToBounds = YES;
[cell.followingCountBtn addTarget:self action:@selector(followingBtnClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[cell.followerCountBtn addTarget:self action:@selector(followerBtnClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
// edit profile becomes follow
cell.editProfileButton.layer.cornerRadius = 3;
cell.editProfileButton.layer.borderColor = UIColorFromRGB(0x1FAA4E).CGColor;
cell.editProfileButton.layer.borderWidth = 1.0f;
cell.editProfileButton.titleLabel.textColor = UIColorFromRGB(0x1FAA4E);
return cell;
}
else if(indexPath.section == 1){
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
return cell;
}
else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"postsCell" forIndexPath:indexPath];
return cell;
}
}
감사
여기 내 전체 코드입니다.
죄송합니다. 무슨 문제입니까? 그것은 부서 지는가? –