【发布时间】:2013-08-09 16:03:31
【问题描述】:
我是 Objective-c 和 iOS 的新手
我创建了几个带有插座的自定义表格单元格。但我不确定我是否使用了正确的方式。
我想要做的是通过表视图控制器中定义的 IBAction 获取自定义单元格内的 Outlet 的属性。
我有一个名为 KolonNumberCell 的自定义表格单元格,其中有一个 UISlider。 我想在 UITableViewController 中定义一个名为 playNumbers 的 IBAction。滑块在自定义单元格中似乎工作正常。我可以得到它的价值。
但我不知道如何在点击 playButton 插座时获取此滑块的值。
如果您能给我一些信息或告诉我方法,我将不胜感激。
提前致谢
TableController.h
#import <UIKit/UIKit.h>
@class KolonNumberCell;
@class BankoNumberCell;
@interface TableViewController : UITableViewController{
NSArray *bundleArray;
IBOutlet KolonNumberCell *kolonCell;
IBOutlet BankoNumberCell *bankoCell;
UIButton *playButton;
}
@property (strong) IBOutlet KolonNumberCell *kolonCell;
@property (strong) IBOutlet BankoNumberCell *bankoCell;
@property (nonatomic,retain) NSArray *bundleArray;
@property (nonatomic,retain) IBOutlet UIButton *playButton;
- (void)playNumbers:(id)sender;
@end
TableController.m 的一部分
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
@synthesize bundleArray,kolonCell,bankoCell,playButton;
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *bundle1 = [[[NSBundle mainBundle] loadNibNamed:@"KolonNumberCell" owner:self options:nil] objectAtIndex:0];
NSArray *bundle2 = [[[NSBundle mainBundle] loadNibNamed:@"BankoNumberCell" owner:self options:nil] objectAtIndex:0];
bundleArray = [[NSArray alloc] initWithObjects:bundle1,bundle2, nil];
}
- (void)playNumbers:(id)sender
{
NSLog(@"button");
// Get the value of the slider in KolonNumberCell... but how?
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
tableView.allowsSelection = NO;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [bundleArray objectAtIndex:indexPath.section];
}
return cell;
}
@end
我的一个 customtableviewcell 实现文件
#import "KolonNumberCell.h"
@implementation KolonNumberCell
@synthesize label,slider;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
self.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"doubleRound.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0]];
}
- (IBAction)sliderChanged:(id)sender
{
[label setText:[NSString stringWithFormat:@"%i",(int)slider.value]];
}
+ (NSString *)reuseIdentifier {
return @"Cell";
}
@end
【问题讨论】:
标签: ios uitableview ibaction