XCode -UILABELはViewDidapearで値を変更していません
-
10-10-2019 - |
質問
みなさん、作成しているiPhoneアプリがあります。 uitableviewを使用して、詳細ビューに表示されます。
詳細ビューでは、スクロールビューがあり、すべてのデータ(XML)が問題なく問題ありません。
Scrollviewの私のuilabelsは正しいデータで更新されますが、サブビューを上に追加し続けてラベルの後にラベルを追加し続け、すべてMumbo Jumboに見えます。
次のようなサブビューを削除しようとするためにすべてを試みました。
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview];
}
と
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
だから私は困惑しています、私は何が起こっているのか分かりませんでした。何か助けがありますか?私はGoogleを年齢とAgesmを探していましたが、うまくいかないのと同じ答えを見つけ続けています:(
あなたが知っていることを助けるかもしれないサイトへの方向性は大歓迎です。
ありがとう!
すべてのscrollviewとラベルをロードするコントローラーにあるものは次のとおりです。
- (void)viewDidAppear:(BOOL)animated {
// Create the scroll view for this view
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 270);
[scrollView setFrame:CGRectMake(0, 198, 320, 170)];
// Do the labels for the text
UILabel *dates = [[UILabel alloc] initWithFrame:scrollView.bounds];
dates.textColor = [UIColor whiteColor];
dates.font = [UIFont boldSystemFontOfSize:12];
dates.text = round_date;
dates.tag = 1;
[dates setBackgroundColor:[UIColor clearColor]];
[dates setFrame:CGRectMake(10, 10, 280, 22)];
[scrollView addSubview:dates];
[dates release];
// Add the content to the main scrollview
[self.view addSubview:scrollView];
[scrollView release];
}
解決
わかりました、その理由は、ビューを提示するたびにviewdidappearが呼ばれることです。
これを行う場合はそうです
-(void) viewDidLoad;
代わりは。
後でそれらにアクセスできるようにするには、uiviewcontrollerでそれらを参照しておくことをお勧めします
-(void) viewDidLoad {
scrollView = [[UIScrollView alloc] initWithFrame];
[self.view addSubview:scrollView];
}
次のようにヘッダーファイルで定義します。
UIScrollView *scrollView;
所属していません StackOverflow