ios - 更改未分段控件时不会加载 Tableview 数据
<p><p>//tableview 没有变化。我已经在这几天了。看起来很简单。谢谢你的帮助</p>
<pre><code>#import "StopsTableViewController.h"
static NSString *MyIdentifier = @"RouteListing";
@interface StopsTableViewController ()
@property (strong, nonatomic) NSArray *TESTARRAY;
@end
@implementation StopsTableViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = ;
if (self) {
//Set the tab bar item's title
self.title = @"Stops";
}
self.stopList = [ fetchStopListing];
self.TESTARRAY = @[@"Josh", @"Kyle", @"Nate"];
return self;
}
- (void)viewDidLoad {
;
forCellReuseIdentifier:MyIdentifier];
// Adds Segmented Control
;
}
- (void)didReceiveMemoryWarning {
;
// Dispose of any resources that can be recreated.
}
- (void) segmentedView {
NSArray *segmentedMenu = ;
UISegmentedControl *segmentedControl = [ initWithItems:segmentedMenu];
[segmentedControl addTarget:self
action:@selector(valueChanged:)
forControlEvents:UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
}
</code></pre>
<h1>pragma mark - 表格 View 数据源</h1>
<pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ( == 0) {
return;
}
else {
return ;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [ initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (_segmentedControl.selectedSegmentIndex == 0) {
cell.textLabel.text = [ objectForKey:@"stoptitle"];
cell.detailTextLabel.text = objectForKey:@"stopnumber"]];
}
else {
cell.textLabel.text = self.TESTARRAY;
}
return cell;
}
</code></pre>
<h1>pragma mark -TableView 委托(delegate)</h1>
<pre><code>// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here, for example:
// Create the next view controller.
StopInfoViewController *detailViewController = [ initWithNibName:@"StopInfoViewController" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.stopInfo = [ objectForKey:@"stopnumber"];
detailViewController.stopName = [ objectForKey:@"stoptitle"];
// Push the view controller.
;
}
//Function for segmentedView
-(void) valueChanged:(UISegmentedControl *)sender {
;
NSLog(@"I'm getting called segment number is: %ld", (long)sender.selectedSegmentIndex);
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在调用 table reload 方法之前检查您的数据源数组,并确保该数组包含与您选择的段相对应的新值。</p></p>
<p style="font-size: 20px;">关于ios - 更改未分段控件时不会加载 Tableview 数据,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31332526/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31332526/
</a>
</p>
页:
[1]