Some settings for UITableView in iOS

Source: Internet
Author: User

Do not slide:

?
1 tableView.userInteractionEnabled = NO;

You can also set the Userinteractionenable property in the storyboard

Show Guide Arrows:

?
12 // 显示导向箭头cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

Custom buttons:

?
12345678910111213141516171819202122 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    staticNSString *ID = @"device";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];        HHDevice *device = self.device[indexPath.row];    // 给cell的控件赋值    cell.textLabel.text = device.nickName;    cell.detailTextLabel.text = device.IMSI;        // 自定义一个button    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];    btn.frame = CGRectMake(0, 0, 55, 25);    btn.backgroundColor = [UIColor clearColor];    btn.tag = indexPath.row;// 给按钮绑定tag,好知道点击的是哪行    [btn setTitle:@"Edit"forState:UIControlStateNormal];        [btn addTarget:self action:@selector(Edit:) forControlEvents:UIControlEventTouchUpInside];        cell.accessoryView = btn;        returncell;}

To set a background image:

?
12345678910111213141516 1.给tableView设置背景view    UIImageView *backImageView=[[UIImageViewalloc]initWithFrame:self.view.bounds];     [backImageView setImage:[UIImageimageNamed:@"liaotianbeijing"]];      self.tableView.backgroundView=backImageView;     2.让cell透明  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {                MyCell  *cell = [tableViewdequeueReusableCellWithIdentifier:@"METext"forIndexPath:indexPath];      cell.backgroundColor=[UIColor clearColor];//关键语句      [cell setCellInfo:dic];//自定义类目方法       returncell;         }

Set the background image for TableView, but if you set the background Backgroundview directly, the background map will not be displayed because the cell on TableView is opaque by default, so the solution is to make the cell transparent.

To set a picture for a cell:

?
1 cell.imageView.image = [UIImage imageNamed:@"childish_folder"];

Cell Swipe Delete function:

?
12345 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    NSLog(@"userId是:%@",_userId);    NSLog(@"长按的行号是:%d",[indexPath row]);}

The Nsinteger output of the input format is%ld:

?
1 NSString *number = [@"NO."stringByAppendingString:[NSString stringWithFormat:@"%ld:", (indexPath.row + 1)]];

If the format is written in%d, Xcode will have a warning.

Some settings for UITableView in iOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.