내가 튜토리얼에 의해 응용 프로그램을 (개발하고 있어요,하지만 튜토리얼은 스위프트를 위해 작성 내가 목표 - C를 배우고 있습니다. 표시 source아이폰 OS 사용자 정의보기는
튜토리얼하지만 문제가 없습니다 나는 단지 장면이 사용자 정의 컨트롤러 중 하나를 사용할 때 작동하는 사용자 정의 컨트롤러 (RatingController)를 개발하고 있어요 사용자 정의 컨트롤러 소스가 여기에 있습니다 :.
@implementation RatingController
//MARK: Properties
const int spacing = 5;
const int starCount = 5;
UIButton *ratingButtons[starCount];
-(void)setRating:(int)rating{
_rating = rating;
[self setNeedsLayout];
}
-(int)getRating{
return _rating;
}
//MARK: Initialization
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
//load the images
UIImage *filledStarImage = [UIImage imageNamed:@"filledStar"];
UIImage *emptyStarImage = [UIImage imageNamed:@"emptyStar"];
for (int i = 0; i < starCount; i++) {
//create button
UIButton *button = [[UIButton alloc]init];
//set the images
[button setImage:emptyStarImage forState:UIControlStateNormal];
[button setImage:filledStarImage forState:UIControlStateSelected];
[button setImage:filledStarImage forState:UIControlStateHighlighted|UIControlStateSelected];
//No additional highlight when switching state
button.adjustsImageWhenHighlighted = false;
//hook up the method which should be executed when the user touches a button
[button addTarget:self action:@selector(ratingButtonTapped:) forControlEvents:UIControlEventTouchDown];
//add the button the the ratingButton array
ratingButtons[i] = button;
//add the button to the view
[self addSubview:button];
}
}
return self;
}
-(void) layoutSubviews{
//Set the button's width and height to the height of the frame.
const int buttonSize = self.frame.size.height;
CGRect buttonFrame = CGRectMake(0, 0, buttonSize, buttonSize);
for(int i = 0; i < starCount; i++){
buttonFrame.origin.x = (i * (buttonSize + spacing));
ratingButtons[i].frame = buttonFrame;
}
[self updateButtonSelectionState];
}
-(CGSize) intrinsicContentSize{
const int buttonSize = self.frame.size.height;
const int width = (buttonSize * starCount) + (spacing * (starCount -1));
return CGSizeMake(width, buttonSize);
}
//MARK: Button Action
-(void) updateButtonSelectionState{
for(int i = 0; i < starCount; i++)
ratingButtons[i].selected = i < _rating;
}
-(void) ratingButtonTapped:(UIButton *) button{
for(int i = 0; i < starCount; i++){
if(ratingButtons[i] == button){
_rating = i + 1;
}
}
[self updateButtonSelectionState];
}
@end
내가 1과 사용자 정의 컨트롤러의 2를 넣었을 때 장면 마지막에 추가 된 것을 볼 수 있습니다 (마지막 목록 항목 만 사용자 정의 컨트롤러를 보여주는 목록에 있음) 누군가가 도와 줄 수 있기를 바랍니다. 이자형.
대단히 감사합니다!
한 장면에서 두 컨트롤러가 무슨 뜻입니까? 컨테이너보기에서 사용하고 있습니까? –
여기처럼 : https://snag.gy/n0jK1h.jpg 모든 목록 항목에 별표가 포함되어야합니다. –
tableview 데이터 소스 코드를 게시 할 수 있습니까? cellForRowAtIndexPath. – JingJingTao