我的[a-z ]+\s*(?:[^a-z]+?\d{2}/\d{2}[^a-z]+?\d+½?[+-]?)+
中有tableview
个UITableview
子类。我添加了三个标签,左边有一个Tbalview.xib
。这是我的代码:
checkBtn
Tableview.h
@interface TableView : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *lab1;
@property (weak, nonatomic) IBOutlet UILabel *lab2;
@property (weak, nonatomic) IBOutlet UILabel *lab3;
@property (weak, nonatomic) IBOutlet UIButton *checkBtn;
Tableview.m
Viewcontroller.m
@implementation TableView
@synthesize lab1 = _lab1;
@synthesize lab2 = _lab2;
@synthesize lab3 = _lab3;
@synthesize checkBtn;
我有两个图像为selectBtn.png(已选择)和DeselectBtn.png(已取消选择)。
我在#import "ViewController.h"
#import "TableView.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation ViewController
{
NSMutableArray *cells_Array;
NSArray *jsonObject;
int selectedIndex;
}
- (void)viewDidLoad {
[super viewDidLoad];
cells_Array = [[NSMutableArray alloc] init];
selectedIndex = -1;
// Do any additional setup after loading the view, typically from a nib.
//NSArray *jsonObject;
jsonObject = @[
@{
@"partner": @"50",
@"gamer": @"199",
@"pointer": @"144"
},
@{
@"partner": @"80",
@"gamer": @"112",
@"pointer": @"11" },
@{
@"partner": @"30",
@"gamer": @"112",
@"pointer": @"14"
},
@{
@"partner": @"50",
@"gamer": @"100",
@"pointer": @"199"
},
@{
@"partner": @"50",
@"gamer": @"19",
@"pointer": @"44"
},
@{
@"partner": @"2000",
@"gamer": @"500",
@"pointer": @"1000"
}
];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSString * jsonString=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// NSLog(@"%@",jsonString);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[cells_Array removeAllObjects];
return [jsonObject count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableView";
TableView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.lab1.text = [jsonObject objectAtIndex:indexPath.row][@"gamer"];
cell.lab2.text = [jsonObject objectAtIndex:indexPath.row][@"partner"];
cell.lab3.text = [jsonObject objectAtIndex:indexPath.row][@"pointer"];
if(indexPath.row == selectedIndex)
{
[cell.checkBtn setSelected:true];
}
[cells_Array addObject:cell];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for (TableView *view in cells_Array ) {
[view.checkBtn setSelected:false];
}
TableView *cellView = [self.containerTableView cellForRowAtIndexPath:indexPath];
selectedIndex = (int)indexPath.row;
[cellView.checkBtn setSelected:true];
}
@end
的帮助下获得了此代码。我是iOS的初学者,因此无法找到我的错误。在我的代码中,他们提供了一些解决方案,但没有调用那两个SO
这是我从SO那里获得帮助的项目。仅适用于相同的代码。但是当我自己尝试时这不起作用。这就是代码Project
以上项目运作良好。就像我尝试过一样,但对于radiobutton来说效果不佳。这是我自己的项目链接own projetc that not wroking