织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

If no items in Array, show No Data La欧博注册bel (Watc

时间:2025-08-03 22:30来源: 作者:admin 点击: 9 次
I'm using Parse to pull in data into a simple Table View. When there is no data I show a label via this: - (NSInteger)numberOfSectionsInTableView:(U

I'm using Parse to pull in data into a simple Table View. When there is no data I show a label via this:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { NSInteger numOfSections = 0; if ([self.stringArray count] > 0) { self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; numOfSections = 1; self.tableView.backgroundView = nil; } else { UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, self.tableView.bounds.size.height)]; noDataLabel.text = @"No data available"; noDataLabel.textColor = [UIColor blackColor]; noDataLabel.textAlignment = NSTextAlignmentCenter; self.tableView.backgroundView = noDataLabel; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } return numOfSections; }

I can't figure out how to do the same thing in WatchKit since Table Views work a bit different. But I'm just showing the same data in the iPhone view as the Watch view.

enter image description here

Here is what I have in my WatchKit InterfaceController.m. I need to add a similar logic to what I do in the TableViewController.m for adding a "No Data" label if there's no data, any ideas how that would work in WatchKit?

- (void)willActivate { // This method is called when watch view controller is about to be visible to user [super willActivate]; [self.myTable setNumberOfRows:[self.data count] withRowType:@"myRows"]; for (NSInteger index = 0; index < [self.data count]; index++) { NSString *title = [self.data objectAtIndex:index]; MyRowController *controller = [self.myTable rowControllerAtIndex:index]; [controller.myLabel setText:title]; NSLog(@"Title: %@", title); } for (NSInteger index = 0; index < [self.dataDate count]; index++) { NSString *titleDate = [self.dataDate objectAtIndex:index]; MyRowController *controller = [self.myTable rowControllerAtIndex:index]; [controller.myLabel2 setText:titleDate]; NSLog(@"TitleDate: %@", titleDate); } }

EDIT: Added per Skylar Lauren answer. Still getting a blank WatchKit scene with no label though.

if ([self.data count] > 0) { UILabel *noDataAvailableLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 15, 15)]; noDataAvailableLabel.hidden = YES; self.myTable.hidden = NO; [self.myTable setNumberOfRows:[self.data count] withRowType:@"myRows"]; for (NSInteger index = 0; index < [self.data count]; index++) { NSString *title = [self.data objectAtIndex:index]; MyRowController *controller = [self.myTable rowControllerAtIndex:index]; [controller.myLabel setText:title]; NSLog(@"Title: %@", title); } for (NSInteger index = 0; index < [self.dataDate count]; index++) { NSString *titleDate = [self.dataDate objectAtIndex:index]; MyRowController *controller = [self.myTable rowControllerAtIndex:index]; [controller.myLabel2 setText:titleDate]; NSLog(@"TitleDate: %@", titleDate); } } else { UILabel *noDataAvailableLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 15, 15)]; self.myTable.hidden = YES; noDataAvailableLabel.hidden = NO; noDataAvailableLabel.text = @"No data available"; noDataAvailableLabel.textColor = [UIColor blackColor]; noDataAvailableLabel.textAlignment = NSTextAlignmentCenter; }

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-08-13 01:08 最后登录:2025-08-13 01:08
栏目列表
推荐内容