我知道我不能调用dIDSelectRowAtIndexPath,因为它是一个委托方法.我尝试使用selectRowAtIndexPath但不调用dIDSelectRowAtIndexPath和willSelectRowAtIndexPath方法.正如这里所说,
https://stackoverflow.com/a/7496926/1050722可以使用一些新方法,然后从另一个VIEwController(detailVIEwController)调用该方法,但该方法应该如何?
这是一些代码:
MasterVIEwController.m
- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self pushDetailVIEwController:indexPath];}-(voID)pushDetailVIEwController:(NSIndexPath *)indexPath{ if (!self.detailVIEwController) { self.detailVIEwController = [[DetailVIEwController alloc] initWithNibname:@"DetailVIEwController" bundle:nil]; } [self.navigationController pushVIEwController:self.detailVIEwController animated:YES]; NSLog(@"pushDetailvIEwC and index %@",indexPath);}
DetailVIEwController.m
-(IBAction)nextItem{ MasterVIEwController *mVc = [[MasterVIEwController alloc] init]; [mVc pushDetailVIEwController:[NSIndexPath indexPathForRow:0 inSection:0]];}
有人能举个例子来解决这个问题吗?谢谢.
编辑:这是新代码
MasterVIEwController.m
- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self pushDetailVIEwController:indexPath];}-(voID)pushDetailVIEwController:(NSIndexPath *)indexPath{ if (!self.detailVIEwController) { self.detailVIEwController = [[DetailVIEwController alloc] initWithNibname:@"DetailVIEwController" bundle:nil]; } self.detailVIEwController.mVc = self; [self.navigationController pushVIEwController:self.detailVIEwController animated:YES]; NSLog(@"pushDetailvIEwC and index %@",indexPath);}
DetailVIEwController.h
#import <UIKit/UIKit.h>#import "MasterVIEwController.h"@interface DetailVIEwController : UIVIEwController <UISplitVIEwControllerDelegate,UItableVIEwDelegate>@property (strong,nonatomic) ID detailitem;@property (strong,nonatomic) IBOutlet UILabel *detailDescriptionLabel;@property (nonatomic,retain) MasterVIEwController *mVc;
DetailVIEwCOntroller.m
-(IBAction)test{ //MasterVIEwController *mVc = [[MasterVIEwController alloc] init]; [self.mVc pushDetailVIEwController:[NSIndexPath indexPathForRow:0 inSection:0]];}
它不会调用方法的NSLog部分,也不会选择行…
解决方法 根据您的问题,这个答案是iPad特定的.主版/明细模板的iPad版本使用UISplitVIEwController两个分割屏幕.此UISplitVIEwController实例保留对两个导航控制器的引用.其中保留了对最顶层视图控制器的引用.这是示例代码,除了测试之外不要逐字使用,因为它不包含错误检查.
// Picking some arbitrary row NSUInteger desiredRow = 3;//???// The Master navigation controller is at index zero in the template,you can check in your app delegate's dIDFinishLaunching: methodUINavigationController *masterController = [self.splitVIEwController.vIEwControllers objectAtIndex:0];// Next we want a reference to the topmost vIEwController again you shouldn't assume it's a UItableVIEwControllerUItableVIEwController *tableController = (UItableVIEwController *)masterController.visibleVIEwController;// Next we get the reference to the tablevIEw in-questionUItableVIEw *tableVIEw = tableController.tableVIEw;// We translate our desired row to an index pathNSIndexPath *path = [NSIndexPath indexPathForRow:desiredRow inSection:0];// We select the row,again this will not call dIDSelectRowAtIndexPath:[tableVIEw selectRowAtIndexPath:path animated:YES scrollposition:UItableVIEwScrollpositionNone];// We call dIDSelectRowAtIndexPath: on the tablevIEw's delegate[tableVIEw.delegate tableVIEw:tableVIEw dIDSelectRowAtIndexPath:path];
当我在详细视图控制器中将此代码放入IBAction方法时,链接按钮执行适当的 *** 作,两者都选择行并推送VC,就像我通过触摸选择了行一样.
总结以上是内存溢出为你收集整理的ios – 从其他ViewController调用didSelectRowAtIndexPath而不响应iPad全部内容,希望文章能够帮你解决ios – 从其他ViewController调用didSelectRowAtIndexPath而不响应iPad所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)