2014-01-28 98 views
-1

我有一个简单的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; 
} 
+0

不,你不必使用数组,但你需要在tableView:numberOfRowsInSection:中返回一个数字。你在做那个吗?显示你的代码。 – rdelmar

+0

现在你的问题没有任何意义。你能提供一些细节/代码片段吗? –

+0

对于numberOfRowsInSection,我已经将它设置为5,因为有5个项目要加载。奇怪的是,调用viewDidLoad时,tableview单位有5个空单元格。然而,当我打电话给[json_tabel reloadData] ...似乎没有发生。 cellForRowAtIndexPath不会被调用。 – Supertecnoboff

回答

0

也许尝试重新加载表视图的数据,一旦你获得字符串的值?

[tableView reloadData]; 
+0

嗯,当我完成解析JSON文件并将需要的数据存储在NSString中时,我调用了reloadData。但它reloadData方法实际上并没有做任何事情......而奇怪的是reloadData似乎发生在viewDidLoad/viewDidAppear上,即使我已经在这些方法中放置了NO代码.... – Supertecnoboff

0

太多的无奈和非常大量的试验和错误的右后我终于想通了,这是因为if (cell == nil),我自定单元没有装(在UITableView中显示)。

我没有意识到这一点在所有的,但是从我在网上读似乎使用带有自定义细胞在故事板UI的UiTableViews时,你是不是想用的控制语句if (cell == nil)

感谢大家谁评论这个帖子,但。我很感激你的帮助。