Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Tableview数据获胜';t更改未分段控件时加载_Ios_Uitableview_Uisegmentedcontrol - Fatal编程技术网

Ios Tableview数据获胜';t更改未分段控件时加载

Ios Tableview数据获胜';t更改未分段控件时加载,ios,uitableview,uisegmentedcontrol,Ios,Uitableview,Uisegmentedcontrol,//tableview没有改变。这件事我已经做了好几天了。看起来很简单。谢谢你的帮助 #import "StopsTableViewController.h" static NSString *MyIdentifier = @"RouteListing"; @interface StopsTableViewController () @property (strong, nonatomic) NSArray *TESTARRAY; @end @

//tableview没有改变。这件事我已经做了好几天了。看起来很简单。谢谢你的帮助

#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 = [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
                         action:@selector(valueChanged:)
               forControlEvents:UIControlEventValueChanged];
    
    segmentedControl.selectedSegmentIndex = 0;
    self.navigationItem.titleView = segmentedControl;
    
}
pragma标记-表视图数据源 pragma标记-表视图委托
在调用table reload方法之前,请检查数据源数组,并确保该数组包含与所选段相对应的新值。

是否设置了tableview委托

尝试将其放入
viewDidLoad
函数中

[tableView setDelegate:self];
[tableView setDataSource:self];
如果您想要更全面的解释,请点击此处:

这篇文章还解释了如何确保类订阅UITableViewDelegate和UITableViewDataSource协议


希望能有所帮助。

在创建表视图时,我经常遇到的一件事是使用interface builder将表与接口连接起来。因为当视图第一次加载时,听起来好像您正在加载数据。但是当您调用
[self.tableView reloadData]
而没有与表建立连接时,将不会发生任何事情


我总是忘记那个超级简单的步骤。希望这对我有所帮助

我对iOS开发还是个新手。你的意思是我需要做些别的事情?如何更改数据源?valueChanged函数正在正确调用,并且在调用tableview重载方法的过程中。调用重载时,将再次调用UITableView数据源。因此,要更改加载到tableview中的数据,您需要更改用于加载tableview的数组中的数据。好的,让我确保我正确理解您的意思。我需要一个数组填充tableview。在valueChanged内部,我需要更改设置视图的数组。这很有效。非常感谢。但是现在,当我单击该选项卡时,表最初是空的。如何立即加载数据?再次感谢是的,你是对的。还要确保委托和数据源设置正确。是的,我没有,我符合委托。我的.h文件中有at设置
// 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 = [[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) valueChanged:(UISegmentedControl *)sender {
     
    [self.tableView reloadData];
    NSLog(@"I'm getting called segment number is: %ld", (long)sender.selectedSegmentIndex);
    
}

@end
[tableView setDelegate:self];
[tableView setDataSource:self];