제목이 혼란스럽게 들릴 경우 죄송합니다. 하지만 테이블보기가있는 응용 프로그램을 만들려고합니다. 각 행에는 고유 한 점 집합이있는 자체 버튼이 있습니다. 나는 버튼이 특정 금액의 포인트를 카운터에 더하고 싶어한다. 그러나, 선택한 행의 NSArray의 int에 액세스하는 방법을 모르겠습니다. 다음은 코드입니다.선택한 행의 NSArray에서 int에 액세스하는 방법?
@interface FBViewController()
@end
@implementation FBViewController {
NSArray *tablePoints;
NSArray *tablePointLabel;
int counter;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//A table that displays the points on the buttons
tablePointLabel = [NSArray arrayWithObjects:
@"10",
@"10",
@"10",
@"20",
@"20",
@"20",
@"30",
@"30",
@"50",
@"70",
@"100",
@"300",
@"300",
nil];
//table of ints (points)
tablePoints = [NSArray arrayWithObjects:
@10,
@10,
@10,
@20,
@20,
@20,
@30,
@30,
@50,
@70,
@100,
@300,
@300,
nil];
counter = 0;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"FBCell";
FBCell *cell = (FBCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FBCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
UIButton *pointButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
pointButton.frame = CGRectMake(250.0f, 5.0f, 75.0f, 30.0f);
[pointButton setBackgroundColor:[UIColor greenColor]];
[pointButton setTitle:[tablePointLabel objectAtIndex:indexPath.row] forState:UIControlStateNormal];
[cell addSubview:pointButton];
[pointButton addTarget:self
action:@selector(addPoint:)
forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(IBAction)addPoint:(id)sender {
counter + [tablePoints objectAtIndex:indexPath.row] = counter;
**//This is where I have an issue. indexPath.row does not work for int arrays. what do i do???**
}
당신과 scottdev에게 감사드립니다! 대신이 방법을 사용했습니다. 그것은 더 단순 해 보였다. 고맙습니다!! – DREW1990
우리 모두는 어딘가에서 시작해야합니다. 기꺼이 도와주세요. (답변을 수락하는 것을 잊지 마세요 :) – timothykc