다음과 같은 방법으로 임의의 단어를 생성하고 있습니다. "wordsToMakeRandomEmail"은 단어의 배열입니다. 나는 스토리 보드를 UITableViewController와 함께 사용하고있다.무작위로 생성 된 단어가 왜 보유되지 않습니까?
검색 막대 컨트롤러가 있습니다. 처음 임의의 전자 메일이 생성되어 UITableViewController의 테이블보기에 표시됩니다. 그러나 셀을 선택하면 무효로 표시됩니다. 어떤 도움이 될 것입니다.
감사합니다.
-(NSString*)getRandomWord
{
NSUInteger randomIndex = arc4random() % [wordsToMakeRandomEmail count];
NSString *string = (wordsToMakeRandomEmail)[randomIndex];
return [string copy];
}
-(NSString*)getRandomEmail
{
NSString *emailPrefix = [self GetRandomWord];
NSString *email = [NSString stringWithFormat:@"%@@google.com",emailPrefix];
return [email copy];
}
그리고 다음 방법은 테이블 셀 건설에 사용되는 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Configure the cell...
NSMutableArray *emails;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
emails = (searchResults)[indexPath.row];
}
else
{
emails = (self.emailConversations)[indexPath.row];
}
EmailData *email = (emails)[0];
if(email.IsReaden && tableView != self.searchDisplayController.searchResultsTableView)
{
ReadEmailTableViewCell *readCell;
readCell = (ReadEmailTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"Read" forIndexPath:indexPath];
readCell.Sender.text = email.Sender;
readCell.Subject.text = email.Subject;
readCell.Time.text = email.Time;
NSString *inStr = [@([emails count]) stringValue];
readCell.Count.text = inStr;
return readCell;
}
else
{
UnReadEmailTableViewCell *unReadCell;
unReadCell = (UnReadEmailTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"UnRead" forIndexPath:indexPath];
NSMutableAttributedString *s =
[[NSMutableAttributedString alloc] initWithString:email.Sender];
[s addAttribute:NSBackgroundColorAttributeName
value:[UIColor yellowColor]
range:NSMakeRange(0, s.length)];
unReadCell.Sender.attributedText = s;
unReadCell.Subject.text = email.Subject;
unReadCell.Time.text = email.Time;
NSString *inStr = [@([emails count]) stringValue];
unReadCell.Count.text = inStr;
unReadCell.Line1.text = email.Line1;
unReadCell.Line2.text = email.Line2;
return unReadCell;
}
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return 115;
}
NSMutableArray *emails = (self.emailConversations)[indexPath.row];
EmailData *email = (emails)[0];
if(email.IsReaden)
{
return 61;
}
return 115;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if([segue.identifier isEqualToString:@"SettingsSegue"])
{
return;
}
NSIndexPath *indexPath = nil;
EmailConversationTableViewController *destViewController = segue.destinationViewController;
NSMutableArray *singleConversation;
if (self.searchDisplayController.active)
{
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
singleConversation = (searchResults)[indexPath.row];
}
else
{
indexPath = [self.tableView indexPathForSelectedRow];
singleConversation = (self.emailConversations)[indexPath.row];
}
destViewController.emails = singleConversation;
}
당신이 셀이 선택됩니다 때 불려갑니다이 당신이 당신의 테이블 뷰 셀과도 코드를 채우는 방법을 보여 주어야한다. 또한 모범 사례 (또는 공통점)는 모든 Objective-C 메소드를 소문자로 시작하는 것입니다. 그래서 "GetRandomEmail'"대신 "getRandomEmail'"을 사용하십시오. "GetRandomWord'"는 "getRandomWord"가되어야합니다. –
@MichaelDautermann getter를위한 objective-c의 일반적인 관행은 또한 'get'이라는 단어를 접두사로 사용하지 않습니다 :) – Tim
그건 사실입니다 @Jeff, Najmul은 ' 이들은'@ 속성들 '이라고 말하지 않습니다. 그리고 저는 그를 부드럽게 해결책으로 인도하려고합니다. 그는 계속 나아가면서 더 좋은 모범 사례를 얻을 것입니다. –