百韵网 >>  正文

rightbarbuttonitem 不显示吗 ios 怎么设置rightbarbuttonitem文字靠右

来源:www.baiyundou.net   日期:较早时间
UITableViewCell类能够显示各种各风格候我需要适应同显示模式显示今文章我使用table view显示系列自定义cell
启Xcode选择"Create a new Xcode project"选择空应用程序模板点击Next命名 CustomCells,照图设置

点击Next选择项目存放路径点击Create
需要添加两文件UITableViewController及custom cell应xib文件
Choose File | New > File 添加名 TableViewController UITableViewController
图:

于controller我并需要xib文件所直接点击Next创建
重新创建文件我创建空 xib 文件图:

点击Next确保Device Family设置iPad再点击Next默认路径保存 CellNib 文件
接着打 CellNib.xib 文件面拖放几 label:

第Label字体27字体System Italic其Label全部都默认设置
步文本依"Label"Label设置tag
第字体Label设置tag=1设置Address1,Address2,Phone,Cell右边Labeltag别2,3,4,5
接着需要修改xibFile's Owner所属类选择 TableViewController

打 TableViewController.h 添加些属性:
#import
@interface TableViewController : UITableViewController

@property (nonatomic, strong) NSArray *cellContent;
@property (nonatomic, strong) IBOutlet UITableViewCell *customCell;

@end
演示我定义数组记录所cell内容需要图设置设置 customCelloutlet

现打TableViewController.m做更改:
#import "TableViewController.h"
@interface TableViewController ()

@end

@implementation TableViewController

@synthesize cellContent, customCell;

- (NSArray *)cellContent
{ cellContent = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"Alex Ander",
@"213 4th St.", @"Apt. 17", @"555-555-5555", @"111-111-1111", nil],
[NSArray arrayWithObjects:@"Jane Doe",
@"4 Any Ave.", @"Suite 2", @"123-456-7890", @"098-765-4321", nil],
[NSArray arrayWithObjects:@"Bill Smith",
@"63 Smith Dr.", @"", @"678-765-1236", @"987-234-4987", nil],
[NSArray arrayWithObjects:@"Mike Taylor",
@"3145 Happy Ct.", @"", @"654-321-9871", @"654-385-1594", nil],
[NSArray arrayWithObjects:@"Nancy Young",
@"98 W. 98th St.", @"Apt. 3", @"951-753-9871", @"951-654-3557", nil],
nil];
return cellContent;
}

- (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;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

#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 [[self.cellContent objectAtIndex:0] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 149.0f;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:.75 alpha:1];
}

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

if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CellNib" owner:self options:nil];
cell = self.customCell;
self.customCell = nil;
}

// Configure the cell…
UILabel *textTarget;
textTarget = (UILabel *)[cell viewWithTag:1]; //name
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:0];
textTarget = (UILabel *)[cell viewWithTag:2]; //addr1
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:1];
textTarget = (UILabel *)[cell viewWithTag:3]; //addr2
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:2];
textTarget = (UILabel *)[cell viewWithTag:4]; //phone
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:3];
textTarget = (UILabel *)[cell viewWithTag:5]; //cellPhone
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:4];
return cell;
}

#pragma mark – Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// …
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}

@end
OK现运行程序特别注意tableViewController默认cell已经我自定义 cell 替代

用种式创建 TableViewCell 能够包含任意控件仅仅Label与ImageFiles's Owner属于TableViewController任何action必须先viewController应类事先定义部另篇文章所谈事情

ios 怎么设置rightbarbuttonitem文字靠右~

Mads Mobæk:给UINavigationBar添加按钮的示例代码  12345678 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:nil action:nil];UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];item.rightBarButtonItem = rightButton;item.hidesBackButton = YES;[bar pushNavigationItem:item animated:NO];[rightButton release];[item release];  但是通常你得有一个Navigation Controller,使你能够写如下代码:  1234 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:nil action:nil];self.navigationItem.rightBarButtonItem = rightButton;[rightButton release];  Amagrammer:楼上的回答非常好,我想再提一些建议:  如果修改后退按钮的标题,必须在先前的view controller里修改,而不是在将要显示的地方修改。就像是说“hey,如果你曾在这个上面放置另一个view controller,那就把后退按钮称为back,而不是default(默认)”。  如果你想在某个特殊状态下隐藏后退按钮,比如显示UIPickerView时,使用self.navigationItem.hidesBackButton = YES;当你退出这一状态时,记得设置回原样。  如果你想显示某个特殊的象征性按钮,使用带有UIBarButtonSystemItemAdd这类控件的initWithBarButtonSystemItem:target:action方法。  记住,符号的意义是由你决定的,但是要小心人机界面交互指南。使用UIBarButtonSystemItemAdd意味着删除一个项目将可能导致你的应用被拒。

1:在Nar上创建label:可以通过UINavigationItem的titleView来实现。 2:添加按钮customNavigationBar.topItem.rightBarButtonItem =[[[UIBarButtonItem alloc]initWithTitle:@"按钮" style:UIBarButtonItemStylePlain target:self action:@sele...

相关要点总结:
(编辑:本站网友)
相关推荐
关于我们 | 客户服务 | 服务条款 | 联系我们 | 免责声明 | 网站地图
@ 百韵网