//tableview 没有变化。我已经在这几天了。看起来很简单。谢谢你的帮助
#import "StopsTableViewController.h"
static NSString *MyIdentifier = @"RouteListing";
@interface StopsTableViewController ()
@property (strong, nonatomic) NSArray *TESTARRAY;
@end
@implementation StopsTableViewController
- (instancetype)initWithNibNameNSString *)nibNameOrNil bundleNSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Set the tab bar item's title
self.title = @"Stops";
}
self.stopList = [[API sharedAPI] fetchStopListing];
self.TESTARRAY = @[@"Josh", @"Kyle", @"Nate"];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MyIdentifier];
// Adds Segmented Control
[self segmentedView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) segmentedView {
NSArray *segmentedMenu = [NSArray arrayWithObjects"All", @"Near Me", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentedMenu];
[segmentedControl addTarget:self
actionselector(valueChanged
forControlEvents:UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
}
- (NSInteger)numberOfSectionsInTableViewUITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {
if ([self.segmentedControl selectedSegmentIndex] == 0) {
return [self.stopList count];
}
else {
return [self.TESTARRAY count];
}
}
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (_segmentedControl.selectedSegmentIndex == 0) {
cell.textLabel.text = [[self.stopList objectAtIndex:indexPath.row] objectForKey"stoptitle"];
cell.detailTextLabel.text = [NSString stringWithFormat"Stop %@", [[self.stopList objectAtIndex:indexPath.row] objectForKey"stopnumber"]];
}
else {
cell.textLabel.text = self.TESTARRAY[indexPath.row];
}
return cell;
}
// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {
// Navigation logic may go here, for example:
// Create the next view controller.
StopInfoViewController *detailViewController = [[StopInfoViewController alloc] initWithNibName"StopInfoViewController" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.stopInfo = [[self.stopList objectAtIndex:indexPath.row] objectForKey"stopnumber"];
detailViewController.stopName = [[self.stopList objectAtIndex:indexPath.row] objectForKey"stoptitle"];
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
//Function for segmentedView
-(void) valueChangedUISegmentedControl *)sender {
[self.tableView reloadData];
NSLog(@"I'm getting called segment number is: %ld", (long)sender.selectedSegmentIndex);
}
@end
在调用 table reload 方法之前检查您的数据源数组,并确保该数组包含与您选择的段相对应的新值。
关于ios - 更改未分段控件时不会加载 Tableview 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31332526/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |