我不确定我做错了什么,但如果有人能指出我正确的方向,我将不胜感激。我正在 xcode 中创建一个应用程序。我目前有两个按钮可以连接到不同的视图控制器,两个视图都由同一个类控制。类中定义了单独的视图。我还有两个数组,每个视图都填充了我想在视图中显示的信息。这是 viewcontrollers .m 文件中的代码。如果我删除出现两个按钮功能的断点,但是第二个按钮显示来自错误数组的信息但转到正确的视图控制器。我完全被难住了。
#import "techTwoViewController.h"
#import "maintInstrctViewController.h"
#import "showTechTipsViewController.h"
@interface techTwoViewController ()
@end
@implementation techTwoViewController
{
NSArray *maintInstrct;
NSArray *techTips;
}
@synthesize tableView;
@synthesize techTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
maintInstrct = [NSArray arrayWithObjects:@"One", @"Two", nil];
techTips = [NSArray arrayWithObjects:@"Three", @"Four", nil];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)techTableView:(UITableView *)techTableView numberOfRowsInSection:(NSInteger)section
{
return [techTips count];
}
- (UITableViewCell *)techTableView:(UITableView *)techTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTechTableIdentifier = @"TechTipsCell";
UITableViewCell *cell = [techTableView dequeueReusableCellWithIdentifier:simpleTechTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTechTableIdentifier];
}
cell.textLabel.text = [techTips objectAtIndex:indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [maintInstrct count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"MaintInstrctCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [maintInstrct objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showMaintKitInstrct"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
maintInstrctViewController *destViewController = segue.destinationViewController;
destViewController.maintKitName = [maintInstrct objectAtIndex:indexPath.row];
}
else if ([segue.identifier isEqualToString:@"showTechTips"]) {
NSIndexPath *indexPath = [self.techTableView indexPathForSelectedRow];
showTechTipsViewController *destViewController = segue.destinationViewController;
destViewController.techTipName = [techTips objectAtIndex:indexPath.row];
}
}
@end