我有一個子類的UIView控件(MyCustomProgressView),我正在編寫用於多個應用程序,每個應用都將被打上標籤,並且想知道如何使控件對我的團隊更加友好。該控件是一個自定義的進度視圖,通常在自定義的UITableViewCell中使用。自定義UITableViewCell中的自定義UIView初始化和默認屬性
MyCustomProgressView有幾個屬性,可以設置爲每個用戶的外觀和行爲。我給了它一個初始值設定項,它將這些設置爲默認值,但希望控件在使用時尊重這些默認值的覆蓋。
例如,在MyCusomProgressView.m:
- (void)awakeFromNib {
[self setup];
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
//initialization
[self setDelegate:nil];
[self setCurrentProgress:0.0f];
[self setLastProgress:0.0f];
[self setAnimated:YES];
[self setProgressColor:[UIColor redColor]];
[self setProgressWidth:7.0f];
[self setTrackWidth:5.0f];
[self setDuration:0.2f];
[self setProgressLabelColor:[UIColor: darkGrayColor];
}
大。現在,當我使用MyCustomTableViewCell的觀點,我想這樣做:
@property (strong, nonatomic) IBOutlet MyCusomProgressView *myProgView;
...
- (void)awakeFromNib {
// Initialization code
[self.myProgView setDuration:0.25f];
[self.myProgView setProgressColor:[UIColor blueColor];
[self.myProgView setProgressLabelColor:[UIColor yellowColor];
[self.myProgView setTrackWidth:2.0];
[self.myProgView setProgressWidth:3.0];
}
的問題是,當MyCustomTableViewCell負載MyCusomProgressView,默認的初始運行並覆蓋自定義設置。我知道我可以爲每次使用修改MyCusomProgressView.m,但如果可能的話,我寧願保留它。
如果它的事項,也有涉及,因爲我已經在故事板所做的這一切非xibs,我不是在做的cellForRowAtIndexPath什麼奇怪不是改變簽名的自定義單元格類其他:
- (MyCustomTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomTableViewCell *cell = (MyCustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
// Configure the cell...
[cell.myProgView setDelegate:self];
return cell;
}
有任何想法嗎?我相信這是一個愚蠢的簡單...
爲了得到你想要做的,你正在設置自定義的TableViewCells在他們的init構造函數中有一個「默認」配置,但是你想在cellForRowAtIndexPath中覆蓋這個配置值(如果需要的話)......這是否正確?我只需要你的信息給你正確的答案:-) – 2014-12-27 19:15:13
不完全。我爲我的子類UIView控件設置了默認值,該控件位於自定義tableviewcell內。我目前正在嘗試覆蓋tableviewcell中的默認值,但自定義UIView的默認值在它們被設置後加載,但他是單元格。如果可能,我希望避免從cellForRowAtIndexPath設置自定義UIView屬性。 – BBruce 2014-12-27 19:57:13