I need to implement a view that acts as a log view, so that when you push a message into it, the message would push other messages upwards. Is there anything like that for iOS?
问问题
65 次
2 回答
3
您可以使用标准 UITableView 轻松实现:
- 每个单元格将负责显示 1 条日志消息
- 新消息到达时将新单元格添加到表格末尾
- 添加单元格后将表格滚动到底部(使用
scrollToRowAtIndexPath:atScrollPosition:animated:
带有UITableViewScrollPositionBottom
位置参数的方法)
这意味着您需要将日志消息存储在数组中,但是如果要显示它们,则无论如何都需要存储消息
于 2012-11-22T10:58:27.600 回答
1
@Vladimir 的答案可能是要走的路,但只是为了看到一些额外的选项,这里有一个使用 UITextView 的示例:
- (IBAction)addNewLog:(UIButton *)sender {
NSString *myInputText = @"some new text from string";
NSString *temp = myTextView.text;
[myTextView setText:[temp stringByAppendingString:[NSString stringWithFormat:@"\n%@: %@",[NSDate date],myInputText]]];
[myTextView setContentOffset:CGPointMake(0, myTextView.contentSize.height - myTextView.frame.size.height) animated:NO];
}
然后,如果您想将文本视图中的文本分成数组中的对象:
NSArray *myAwesomeArray = [myTextView.text componentsSeparatedByString:@"\n"];
请注意,如果“myInputText”字符串曾经包含换行符,则上述内容会中断。
于 2012-11-22T11:19:52.230 回答