我有一個簡單的iOS應用程序,它分析多個JSON訂閱源並將數據存儲在多個字符串中。我確切知道使用哪些字符串來計算計數的內容和時長,因爲JSON訂閱源是我從我的某些網站控制的訂閱源。通過字符串填充UITableView?
然而,即使我在「的tableView的cellForRowAtIndexPath」方法指定這一點,UITableView的仍然不會填充..
這是因爲我使用的字符串來填充的UITableView?如果是這樣,你是否需要使用數組來填充UITableView。
感謝您的時間:)
更新:這裏是M碼:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Printing table view.");
static NSString *CellIdentifier = @"Cell";
AccountCell *cell = (AccountCell *)[account_table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AccountCell" owner:self options:nil];
cell = [nib objectAtIndex: 0];
// Draws the cell background.
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uiFeedletsnglass5.png"]];
// Draws the pressed cell background.
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-on.png"]];
// Round of edges of content view in Carousel.
cell.layer.cornerRadius = 5;
cell.layer.masksToBounds = YES;
cell.layer.borderWidth = 1.0f;
cell.layer.borderColor = [[UIColor grayColor] CGColor];
cell.profilepic.layer.cornerRadius = 5;
cell.profilepic.layer.masksToBounds = YES;
cell.profilepic.layer.borderWidth = 1.0f;
cell.profilepic.layer.borderColor = [[UIColor grayColor] CGColor];
}
if ((facebook_printed == 0) && (logged_facebook == 1)) {
NSString *full_name = [NSString stringWithFormat:@"%@ %@", facebook_first_name, facebook_last_name];
cell.username.text = [NSString stringWithFormat:@"%@", full_name];
cell.account_type_name.text = [NSString stringWithFormat:@"Facebook"];
NSData *facebook_imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: facebook_proffile_pic]];
UIImage *facebook_image = [[UIImage alloc] initWithData:facebook_imageData];
cell.profilepic.image = facebook_image;
facebook_printed = 1;
}
else if ((youtube_printed == 0) && (logged_youtube == 1)) {
cell.username.text = [NSString stringWithFormat:@"%@", youtube_profilename];
cell.account_type_name.text = [NSString stringWithFormat:@"YouTube"];
NSData *youtube_imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: youtube_profilepic]];
UIImage *youtube_image = [[UIImage alloc] initWithData:youtube_imageData];
cell.profilepic.image = youtube_image;
youtube_printed = 1;
}
else if ((instagram_printed == 0) && (logged_instagram == 1)) {
cell.username.text = [NSString stringWithFormat:@"%@", instagram_name_tag];
cell.account_type_name.text = [NSString stringWithFormat:@"Instagram"];
NSData *instagram_imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: instagram_profilepicture]];
UIImage *instagram_image = [[UIImage alloc] initWithData:instagram_imageData];
cell.profilepic.image = instagram_image;
instagram_printed = 1;
}
else if ((googleplus_printed == 0) && (logged_googleplus == 1)) {
cell.username.text = [NSString stringWithFormat:@"%@", googleplus_profilename];
cell.account_type_name.text = [NSString stringWithFormat:@"Google Plus"];
NSData *googleplus_imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: googleplus_profilepic]];
UIImage *googleplus_image = [[UIImage alloc] initWithData:googleplus_imageData];
cell.profilepic.image = googleplus_image;
googleplus_printed = 1;
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
return cell;
}
不,你不必使用數組,但你需要在tableView:numberOfRowsInSection:中返回一個數字。你在做那個嗎?顯示你的代碼。 – rdelmar
現在你的問題沒有任何意義。你能提供一些細節/代碼片段嗎? –
對於numberOfRowsInSection,我已經將它設置爲5,因爲有5個項目要加載。奇怪的是,調用viewDidLoad時,tableview單位有5個空單元格。然而,當我打電話給[json_tabel reloadData] ...似乎沒有發生。 cellForRowAtIndexPath不會被調用。 – Supertecnoboff