我的应用程序出现问题。
我有3个View控制器,我们将它们命名为Oil
,App
和Prop
。这3个视图控制器嵌入在导航控制器中。在那些视图控制器中,我得到了3个表视图。
所以从上到下,从左到右:
Prop View Controller
- > Prop Detail View Controller
Oil View Controller
- > Oil Detail View Controller
- > Web View Controller
App View Controller
- > App Detail View Controller
所以在中间(Oil
)一切正常,我点击一个单元格,显示Oil Detail View Controller
,其中包含我通过Segue传递的信息。
OilViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *sectionTitle = [aromaSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionAroma = [tableData objectForKey:sectionTitle];
aromaNom = [sectionAroma objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"Detail" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"Detail"]) {
OilDetailViewController *test = segue.destinationViewController;
test.aromaName = aromaNom;
test.botaniqueName.text = botaniqueName;
}
}
我还在Oil Detail View Controller
和Web View Controller
之间执行Segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"webView"]) {
NSLog(@"Segue is catched");
WebViewViewController *webView = segue.destinationViewController;
webView.aromaUrl = _aromaName;
}
}
我点击橙色按钮,它会显示网页视图。
但是现在,如果我在Prop
或App
中执行相同操作,则无法正常工作。
例如在Prop Detail VC
中,我得到了一个显示所选属性的标签,但在向我显示标签中选择的正确属性之前,它会显示带有包含旧选定属性的标签的视图控制器。所以我在我的导航控制器中显示了2 Prop Detail View
和<{1}}。
我制作了模拟器的视频:http://videobam.com/VwgLx
PropViewController.m
中的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *sectionTitle = [aromaPropSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionProp = [propData objectForKey:sectionTitle];
propName = [sectionProp objectAtIndex:indexPath.row];
NSLog(@"prop name = %@", propName);
[self performSegueWithIdentifier:@"PropDetail" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"PropDetail"]) {
PropDetailViewController *propView = segue.destinationViewController;
propView.propStr = propName;
NSLog(@"PREPARE FOR SEGUE PROP VIEW CONTROLLER");
}
}
在PropDetailViewController.m
:
- (void)viewDidLoad {
[super viewDidLoad];
self.propLabel.text = _propStr;
NSLog(@"VIEW DID LOAD PROP DETAIL");
// Do any additional setup after loading the view.
}
最后是日志:
在此先感谢您的帮助,我坚持这一点,我的团队中没有人知道iOs。所以我一个人就这么做!
答案 0 :(得分:0)
所以我终于设法找到了一个合适的解决方案..我仍然不知道为什么它在Oil
上起作用并导致其他视图出现问题但仍然存在;这是解决方案:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *sectionTitle = [aromaPropSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionProp = [propData objectForKey:sectionTitle];
propName = [sectionProp objectAtIndex:indexPath.row];
NSLog(@"prop name = %@", propName);
[self performSegueWithIdentifier:@"PropDetail" sender:self];
}
删除上述方法。并且在prepareForSegue方法中执行此方法中的所有操作:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"PropDetail"]) {
PropDetailViewController *propView = segue.destinationViewController;
NSIndexPath *indexPath = [self.propTableView indexPathForSelectedRow];
NSString *sectionTitle = [aromaPropSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionApp = [propData objectForKey:sectionTitle];
NSString *name = [sectionApp objectAtIndex:indexPath.row];
propView.propStr = name;
}
}
现在它运作正常!但是它在某个地方起作用并不是逻辑,而在另一个地方不起作用。