导航到自定义表视图单元格按钮操作中的另一个Viewcontroller

时间:2013-10-02 10:33:05

标签: iphone uitableview ios7 uibutton

我有一个TableViewCell,其中有一个按钮Zoom Button。当我单击“缩放”按钮时,视图将导航到PlayerViewController。

https://www.dropbox.com/s/ikmj4vdfc407ldy/customcell.png

这是播放按钮的代码。

-(IBAction)downloadAction:(id)sender 
{
            BookPlayerViewController *bookPlayerViewController=[BookPlayerViewController alloc];
            [self.navigationController pushViewController:bookPlayerViewController animated:YES];
}

我该如何解决这个问题?我正在使用Nib而不是故事板来实现项目。

4 个答案:

答案 0 :(得分:1)

您没有初始化笔尖名称。您需要使用NibName初始化BookPlayerViewController以显示它,

使用 IB

BookPlayerViewController *vcBookPlayerViewController = [[BookPlayerViewController alloc] 
initWithNibName:@"BookPlayerViewController" bundle:nil]; 

使用故事板

BookPlayerViewController *vcBookPlayerViewController = [storyboard
instantiateViewControllerWithIdentifier:@"BookPlayerViewController"];

答案 1 :(得分:1)

I  created an outlet property in the tableviewcell class
@property (retain, nonatomic) IBOutlet UIButton *zoomButton;

然后我在tableviewCellForRowAtIndex方法的超类中添加目标

[cell.zoomButton addTarget:self action:@selector(navigateAction:) forControlEvents:UIControlEventTouchUpInside];

然后我接受了navigationAction的IBAction,我编写了从一个ViewController导航到另一个ViewController所需的那些动作。

-(IBAction)navigateAction:(id)sender

{

*UIButton *btn = (UIButton *)sender;
int indexrow = btn.tag;
NSLog(@"Selected row is: %d",indexrow);

currentBook = [[bookListParser bookListArray] objectAtIndex:indexrow];

KitapDetayViewController *kitapDetayViewController;
if(IS_IPHONE_5)
{
    kitapDetayViewController = [[KitapDetayViewController alloc] initWithNibName:@"KitapDetayViewController" bundle:Nil];
}

else
{
    kitapDetayViewController = [[KitapDetayViewController alloc] initWithNibName:@"KitapDetayViewController_iPhone4" bundle:Nil];
}
kitapDetayViewController.bookId=currentBook.bookId;
kitapDetayViewController.detailImageUrl = currentBook.detailImageUrl;
kitapDetayViewController.bookAuthor = currentBook.bookAuthor;
kitapDetayViewController.bookName = currentBook.bookName;
kitapDetayViewController.bookDescription = currentBook.bookDescription;
kitapDetayViewController.bookNarrator=currentBook.bookNarrator;
kitapDetayViewController.bookOrderHistory=currentBook.bookOrderDate;
int byte=[currentBook.bookSizeAtByte intValue];
int mb=byte/(1024*1024);
NSString *mbString = [NSString stringWithFormat:@"%d", mb];
kitapDetayViewController.bookSize=mbString;
kitapDetayViewController.bookOrderPrice=currentBook.priceAsText;
int second=[currentBook.bookDuration intValue];
int minute=(second/60)%60;
int hour=(second/3600)%60;
int sec = second % 60;

NSString *formattedTime = [NSString stringWithFormat:@"%d:%d:%d", hour, minute, sec];
kitapDetayViewController.bookDuration=formattedTime;
kitapDetayViewController.chapterNameListArray=self.chapterNameListArray;
// [[bookListParser bookListArray ]release];
[self.navigationController pushViewController:kitapDetayViewController animated:YES];*

}

这样我就解决了这个问题。

答案 2 :(得分:0)

如果您正在加载nextview的笔尖

,请尝试这种方式
BookPlayerViewController *vcBookPlayerViewController = [[BookPlayerViewController alloc] initWithNibName:@"BookPlayerViewController" bundle:nil]; 
[self.navigationController pushViewController:vcBookPlayerViewController animated:YES];

答案 3 :(得分:0)

你错过了笔尖检查这段代码..

-(IBAction)downloadAction:(id)sender 
{
            BookPlayerViewController *bookPlayerViewController=[BookPlayerViewController alloc]initWithNibName:@"BookPlayerViewController" bundle:nil];;
            [self.navigationController pushViewController:bookPlayerViewController animated:YES];
}