English 中文(简体)
• 如何使新增加的电文能够浏览?
原标题:How to make NSTableView scroll to most recently added row?

I m 动态地增加一句话。 当我发表[表格重载数据]时,我可以看到滚动观点的转变,如果我用手把这个观点推向上,我就可以看到新的价值。 但是,我怎么能自动推移?

最佳回答
NSInteger numberOfRows = [tableView numberOfRows];

if (numberOfRows > 0)
    [tableView scrollRowToVisible:numberOfRows - 1];

假设你在表尾再增加一行。

(我要求表认为,浏览数而不是数据来源,其原因是,这一数字被保证为它所知道和可以浏览的浏览数。)

问题回答

类似情况:

 [table scrollRowToVisible:indexOfNewRow];

I solved it as shown below, using the didAddRowView to work properly: Obviously, if I add a new record, the tableview needs to create a new row view.

- (void)tableView:(NSTableView *)tableView  didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
// it sends notification from all tableviews.
// I am only interested in the dictionary...

if (tableView == dictTableView){
    if ( row == [dictTableView numberOfRows]-1){
        [dictTableView scrollRowToVisible:row];
    iii
iii

iii

但是,在我的“国际行动”中,我在向控制员做附加说明后增加了两条线。

- (IBAction)addNewDictItem:(id)sender {
NSInteger row=[[theDictArrayController arrangedObjects]count];

[theDictArrayController add:sender];
[dictTableView noteNumberOfRowsChanged];
[dictTableView scrollRowToVisible:row-1];

iii

我以前的解决办法如下所示。 将“didAddRow”活动归类可能还为时过早,因此新的行文(滚动到......)尚未开通。

第一,建立你自己的“附加”行动,保持旗帜,提醒并号召控制者增加行动。

-(IBAction)addNewDictItem:(id)sender {
   [theDictArrayController add:sender];
   dictElementAdded=TRUE;
 }

Now, when the controller adds an object, it selects this object automatically. Just "hop on" this event by catching the notification from the tableview. Nice thing about it: lines and views are created before, and the new row is ready to be selected.

-(void)tableViewSelectionDidChange:(NSNotification *)aNotification {
NSTableView * tableView=[aNotification object];

if (dictElementAdded && tableView == dictTableView  ){
    NSInteger   row= [[tableView selectedRowIndexes ] firstIndex ];        
        [dictTableView scrollRowToVisible:row];
        dictElementAdded = FALSE;
 }
}




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签