2014-04-19 55 views
0

我正在为学校制作一个项目,并且我在表格视图控制器遇到问题,我想添加一个按钮将其链接到另一个页面,它真的是它,所以我有一个7个表格单元格的列表连接到详细视图控制器,从那里我想添加一个按钮,将链接到另一个页面,但每7个表格单元格需要去不同的网页,对不起,我不是很擅长解释的东西,但如果有人可以帮助我会非常感激。TableViewController按钮连接

TableViewController.m

#import "tableViewController.h" 
#import "TableCell.h" 
#import "DetailViewController.h" 

@interface tableViewController() 

@end 

@implementation tableViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
self = [super initWithStyle:style]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

// Uncomment the following line to preserve selection between presentations. 
// self.clearsSelectionOnViewWillAppear = NO; 

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
// self.navigationItem.rightBarButtonItem = self.editButtonItem; 

_Title [email protected][@"Centrum Advance", @"Elite Whey Protein", @"USP LABS Jack3d", @"NitroCore 24", @"PHD Synergy ISO 7", @"REFLEX One Stop", @"MET-Rx G.C.M.O"]; 

[email protected][@"1C.jpg",@"2C.jpg",@"3C.jpg",@"4C.jpg",@"5C.jpg",@"6C.jpg",@"mets.jpg",]; 

[email protected][@"Not Reviewed",@"'I'm a big fan of whey protein becasue the dosing is simple, easy to consume, and usually a lot cheaper than pills. I use to use the regular old GNC 100% whey protein which was good to take after a workout, but I really wanted more from my supplements. Proto Whey had a lot of great reviews and I have to say, it worked pretty well for me.'",@"'Wow. This stuff is amazing. No fillers, the taste (lemon-lime) isn't overwhelming, and I can work out solid for 1.5 hours and still feel like a beast. I've taken NO-Xplode and Black Powder, and I find that Jack3d provides more energy, while something like Black Powder gives me more pump. This is why I mix a scoop of Black Powder and a scoop of Jack3d and get totally effed at the gym.I've come to notice that if I take jack3d later in the day, it really messes with my sleep, and I contribute that to the DMAA in it, which is a stimulant. I just finished a bottle and I notice my tolerance was going up. On days that I was taking just jack3d, since I like to mix it up, I moved up to 2 scoops towards the end of the bottle. So all in all, awesome for energy in the gym, only somewhat decent regarding pump. But I still give it a solid 9. I have yet to try out 1.M.R, which I will be getting next week, and can find out then which is better for me.BTW I didn't get a 'crash' that so many people speak of, this could be that maybe I am not just prone to the type of thing, and that I work out after I get off work, so 'crashing' really doesn't matter for me.'",@"Not Reviewed",@"'I had the double chocolate flavor and it was the BEST tasting stuff I've ever had. It was so good, sometimes I just took a serviing for breakfast if I was running short on time. The effectiveness was good too, and after finishing a tub of it, I noticed just about all of my lifts increased. I gained some great vascularity in my bi's, and my chest strength exploded. Honestly, for all of you who want to spend a little money and get a nice supplement...this is your winner. I am definitely gonna use this for a while until I get sick of the taste or see a new up-and-coming product. Only reason I give value a 5 is because I paid about $40 for the 2LB tub back in January.'",@"Not Reviewed",@"Not Reviewed",]; 

[email protected][@"1.2KG",@"3KG",@"2.7KG",@"3.9KG",@"5KG",@"6.4KG",@"0.5KG",]; 

[email protected][@"The perfect whey protein to aid weight loss or pack on lean muscle mass",@"Add some   serious muscle to your body without the fat!",@"24g of protein per scoop for just 112 calories and no sugars!",@"Premium Whey Isolate",@"Minimal carbohydrates and fats",@"The Only Way To Enjoy Whey Protein",@"27g of protein with each serving",]; 

} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
return _Title.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TableCell"; 
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

// Configure the cell... 

    int row = [indexPath row]; 

    cell.TitleLabel.text = _Title[row]; 
    cell.ThumbImage.image = [UIImage imageNamed:_Images[row]]; 
cell.Review1.text = _Review[row]; 
cell.Size1.text = _Size[row]; 
cell.Does1.text = _Does[row]; 

    return cell; 
} 

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if([[segue identifier] isEqualToString:@"ShowDetails"]) { 
     DetailViewController *detailviewcontroller = [segue destinationViewController]; 

    NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 

    int row = [myIndexPath row]; 
    detailviewcontroller.DetailModal = @[_Title[row],_Images[row]]; 
    } 
} 
@end 

DetailViewController.m

#import "DetailViewController.h" 

@interface DetailViewController() 

@end 

@implementation DetailViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
_TitleLabel.text = _DetailModal[0]; 
_ThumbImage.image = [UIImage imageNamed:_DetailModal [1]]; 

self.navigationItem.title = _DetailModal[0]; 

} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

@end 

表cell.m为空,.H用于IBOutlets

回答

0

上创建一个公共@property DetailViewController,您可以在prepareForSegue:sender:中设置TableViewController以在每个单独的DetailViewController中设置按钮的目标。

// DetailViewController.h 
@interface DetailViewController  
@property NSInteger nextPageId; // or whatever 

// TableViewController.m 
// prepareForSegue... 
detailviewcontroller.nextPageId = myIndexPath.row; // something like this 

// DetailViewController.m 
// viewDidLoad... 
[myButton addTarget:self action:@selector(myButtonHandlerMethod) forControlEvents:UIControlEventTouchUpInside]; 

-(void)myButtonHandlerMethod { 
    // code to present the next "page" based on self.nextPageId 
} 

当用户点击该按钮被称为addTarget:action:forControlEvents:设置的另一种方法myButtonHandlerMethod的方法。如果UIButton位于DetailViewController Storyboard中,则创建一个IBOutlet属性并将该按钮引用为self.myButton

+0

感谢您的帮助,我开始明白要做什么,但仍然有问题了解按钮将如何链接 – user3293705

+0

这有帮助吗?你真的需要一个更具体的问题在本网站获得适当的帮助... –

+0

很高兴帮助。如果你想继续学习你的课程项目(我实际上使用了本书的iOS 6版本),请查阅[Matt Neuberg](http://www.apeth.net/matt/default.html#cocoathings)的两本书我去年参加了一个研究生班。) –