开发者

Working with views

开发者 https://www.devze.com 2023-02-16 11:39 出处:网络
in my App I have 3 UIViews (3 .xib) and 3 buttons for every view one button but the problem that I didn\'t know how to program the views always I have errors and warning I tried to make the view appea

in my App I have 3 UIViews (3 .xib) and 3 buttons for every view one button but the problem that I didn't know how to program the views always I have errors and warning I tried to make the view appear like the info button in the utility application but I must make a back to the original view and I faced problem with delegation

So is there any way to make the view appear by pressing its button exactly like a TabBareController because I want the buttons always exists in every view and I don't want to use an application that uses a tab bar.

Thanks

Edit:

in the firstViewControler.m

- (void)viewDidLoad {

//Load the image   
UIImage *buttonImage = [UIImage imageNamed:@"bt_tweet_S.png"];

//create the button and assign the image
UIButton *tweet = [UIButton buttonWithType:UIButtonTypeCustom];
[tweet setImage:buttonImage forState:UIControlStateNormal];

//sets the frame of the button to the size of the image
tweet.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

//creates a UIBarButtonItem with the button as a custom view
UIBarButtonItem *tweetbar = [[UIBarButtonItem alloc] initWithCustomView:tweet];

tweetbar.tag = 1;

//Load the image   
UIImage *pageImage = [UIImage imageNamed:@"bt_web.png"];

//create the button and assign the image
UIButton *page = [UIButton buttonWithType:UIButtonTypeCustom];
[page setImage:pageImage forState:UIControlStateNormal];
[page addTarget:self action:@selector(flipAction:) forControlEvents:UIControlEventTouchUpInside];
//sets the frame of the button to the size of the image
page.frame = CGRectMake(0, 0, pageImage.size.width, pageImage.size.height);
开发者_如何学运维
//creates a UIBarButtonItem with the button as a custom view
UIBarButtonItem *pagebar = [[UIBarButtonItem alloc] initWithCustomView:page];

pagebar.tag = 2;

//Load the image   
UIImage *infoImage = [UIImage imageNamed:@"bt_info.png"];

//create the button and assign the image
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
[infoButton setImage:infoImage forState:UIControlStateNormal];
[infoButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
//sets the frame of the button to the size of the image
infoButton.frame = CGRectMake(0, 0, infoImage.size.width, infoImage.size.height);

//creates a UIBarButtonItem with the button as a custom view
UIBarButtonItem *infoBar = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
//infoBar.target= self;
//infoBar.action= @selector(showInfo:);
//infoBar.tag = 3;
UIBarItem* space = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                     UIBarButtonSystemItemFlexibleSpace target:nil  action:nil] autorelease];

_toolbar = [[UIToolbar alloc] initWithFrame:
            CGRectMake(0, 460 - 44, 320, 44)];
_toolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
_toolbar.tintColor = [UIColor blackColor];
_toolbar.items = [NSArray arrayWithObjects:space,tweetbar, space,pagebar,space,infoBar,space, nil];


[self.view addSubview:_toolbar];

[tweetbar release];

[super viewDidLoad];
}

and in every view the same code


From what I can squeeze out of your posts, you want to be able to move between 3 views in random orders. Using a navigation controller and pushViewController:/popViewController: is not very good for this.

Better use a tab bar.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号