当前位置: 代码迷 >> Iphone >> 关于多标签视图的有关问题
  详细解决方案

关于多标签视图的有关问题

热度:167   发布时间:2016-04-25 06:48:54.0
关于多标签视图的问题
界面如下图



当我点击第二个标签 single的时候,界面就直接跳出来了,直接调到模拟器的主界面了,怎么回事?



那个标签页的.h代码:如下

C/C++ code
#import <UIKit/UIKit.h>@interface SingleComponentPickerViewController : UIViewController<UIPickerViewDelegate,UIPickerViewDataSource>{    IBOutlet UIPickerView  *singlepicker;    NSArray *pickerdate;    }@property (nonatomic,retain) UIPickerView *singlepicker;@property (nonatomic,retain) NSArray *pickerdate;-(IBAction)buttonpressed;@end




标签页 .m 代码

C/C++ code
#import "SingleComponentPickerViewController.h"@implementation SingleComponentPickerViewController@synthesize singlepicker;@synthesize  pickerdate;// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad./*- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization.    }    return self;}*//*// Implement loadView to create a view hierarchy programmatically, without using a nib.- (void)loadView {}*/-(IBAction)buttonpressed{    NSInteger row=[singlepicker selectedRowInComponent:0];//select the frist singlepicker    NSString *select=[pickerdate objectAtIndex:row];    NSString *title=[[NSString alloc]initWithFormat:@"you select %@",select];    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title                                                message:@"thanks you for choosing"                                                delegate:nil                                       cancelButtonTitle:@"you are welcome"                                        otherButtonTitles:nil];    [alert show];    [alert release];    [title release];}// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {    NSArray *array=[[NSArray alloc] initWithObjects:@"Luke",@"Leia",@"Han",@"Chewbacca",@"Artoo",@"Threepio",@"Lando",nil];    self.pickerdate=array;    [array release];    [super viewDidLoad];}/*// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    // Return YES for supported orientations.    return (interfaceOrientation == UIInterfaceOrientationPortrait);}*/- (void)didReceiveMemoryWarning {    // Releases the view if it doesn't have a superview.    [super didReceiveMemoryWarning];        // Release any cached data, images, etc. that aren't in use.}- (void)viewDidUnload {        [super viewDidUnload];    // Release any retained subviews of the main view.    // e.g. self.myOutlet = nil;}- (void)dealloc {    [singlepicker release];    [pickerdate release];    [super dealloc];}#pragma mark -#pragma mark Picker Data Source Methods-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{    return 1;}-(NSInteger)pickerView:(UIPickerView*)pickerView numberOfRowInComponent:(NSInteger)component{    return [pickerdate count];}#pragma mark Picker delegate Methods-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{    return [pickerdate objectAtIndex:row];}@end


------解决方案--------------------
不知道你在IB中怎么链接的~
  相关解决方案