我有任務來開發應用程序與詞計數和顯示在運行時生成uiscrollview與uilabel作爲子視圖。如何從uiscroll視圖運行時獲取當前uilabel文本
這個過程就好像當用戶在當時加載頁面的時候1000個單詞將填充rutime生成的uilabel和scrollview一樣,並且所有的東西都是從運行時設置的。但它的應用程序,我們有一個按鈕來添加按鈕點擊當前uilabel文本。
和單詞隨機來自數據庫。當我點擊按鈕時,它給了我不同的單詞。從滾動視圖顯示的單詞。
以下是我的代碼以滾動視圖填寫的UILabel數據:
wordName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 2)];
[wordNameArray addObject:wordName];
int i = 0;
for (i = 1; i <= kNumImages; i++)
{
randomN = [wordNameArray objectAtIndex:arc4random() % [wordNameArray count]];
UIImage *image = [UIImage imageNamed:@"word_bg.png"];
word = [[UILabel alloc]initWithFrame:CGRectMake(15,12,250,120)];
[word setFont:[UIFont fontWithName:@"Helvetica-Bold" size:36.0f]];
word.textColor = [UIColor whiteColor];
word.lineBreakMode = UILineBreakModeWordWrap;
word.numberOfLines = 2;
word.textAlignment = UITextAlignmentCenter;
word.backgroundColor = [UIColor clearColor];
[word setText:randomN];
lblWord.text = word.text;
word.tag = i;
NSLog(@"tag no:%d",word.tag);
imageView = [[UIImageView alloc] initWithImage:image];
[imageView addSubview:word];
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
//NSLog(@"%@",word.text);
//NSLog(@"%@",lblWord.text);
// [scrollView1 addSubview:l];
[scrollView1 addSubview:imageView];
touchToSee.hidden = TRUE;
[imageView release];
}
[self layoutScrollImages];
以下是我的滾動事件得到來自標籤的字,但它給我從數組最後一個字:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
touchToSee.hidden = TRUE;
NSLog(@"word-%@",word.text);
}
而其他當我上按鈕我沒有得到完美的作品點擊所以這下面是我的代碼:
NSString *getword = [NSString stringWithFormat:@"%@",word.text];
NSLog(@"lblCountdownBackward:%@",word.text);
所以請幫助我,並提供一些示例代碼,如果可能的話。
在此先感謝。