Xin chào, tôi cần đặt nút ở bên phải, trong thanh điều hướng, lập trình, để nếu tôi nhấn nút, tôi sẽ thực hiện một số thao tác. Tôi đã tạo thanh điều hướng, theo lập trình;Thêm nút vào thanh điều hướng theo chương trình
navBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0,320,44) ];
Tương tự, tôi cần thêm nút, ở bên phải thanh điều hướng này. Cho rằng tôi sử dụng,
1.
UIView* container = [[UIView alloc] init];
// create a button and add it to the container
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 130, 44.01)];
[container addSubview:button];
[button release];
// add another button
button = [[UIButton alloc] initWithFrame:CGRectMake(160, 0, 50, 44.01)];
[container addSubview:button];
[button release];
// now create a Bar button item
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
// set the nav bar's right button item
self.navigationItem.rightBarButtonItem = item;
[item release];
2.
UIImage *im;
im=[UIImage imageNamed:@"back.png"];
[button setImage:im forState:UIControlStateNormal];
[im release];
backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[backButton setImageInsets:UIEdgeInsetsMake(0, -10,5, 5)];
[self.navigationItem setRightBarButtonItem:backButton];
3.
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStylePlain target:self action:@selector(refreshLogsAction:)];
self.navigationItem.rightBarButtonItem = refreshItem;
[refreshItem release];
Tôi đã thử tất cả các cách này, nhưng không có cách nào hiển thị nút ở phía bên tay phải.
tôi cần phải thêm dấu hai chấm để chọn - "hành động: @selector (flipView :)]; – Rydell