我有一个简单的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