私は基本的にこの質問と同じ問題を抱えています。しかし、何だと思いますか?その質問には良い答えがありません。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if([indexPath row] == 0){
UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];
if( aCell == nil ) {
aCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SwitchCell"];
aCell.textLabel.text = @"Colors";
aCell.selectionStyle = UITableViewCellSelectionStyleNone;
/*
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
aCell.accessoryView = switchView;
[switchView setOn:NO animated:NO];
[switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
*/
UIStepper *stepperView = [[UIStepper alloc] initWithFrame:CGRectZero];
NSLog(@"The stepper is %@", stepperView);
aCell.accessoryView = stepperView;
[stepperView setMaximumValue:10];
[stepperView setMinimumValue:0];
[stepperView addTarget:self action:@selector(stepperChanged) forControlEvents:UIControlEventValueChanged];
NSLog(@"The stepper is %@", stepperView);
}
return aCell;
}
UITableViewCell *aCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SwitchCell"];
NSString *s = @"foo";
s = [s stringByAppendingFormat:@"%d", [indexPath row]];
aCell.textLabel.text = s;
return aCell;
}
したがって、コードをコメントアウトされたコードに切り替えると、問題なく動作します (UISwitch が表示されます)。だから私がやろうとしたのは、UISwitchをUIStepperに置き換えることだけで、表示されません。私はobjective-cが嫌いです。
ああ、両方の printlines は、値が (null) であることを示しています。作った直後はヌル?
編集:iOS 5.0。答えは、これがなぜなのかに関係しているように感じます:
NSLog(@"%@", [[UISwitch alloc] init]);
null ではない
NSLog(@"%@", [[UIStepper alloc] init]);
無効です。