How to update row values and children when row of outline view is expanded each time it is clicked












0















I am new in objective c. And I have been looking for examples/answer that describes the outline view expansion of items. Now what I am trying to do is, mark all items as expandable. Now when the user clicks to expand the item, it calls the API, inserts its children if any, and then reload the table view. The Code is given below:



 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item{
//initially make all items expandable to check and load data later on
return YES;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item{
if (item == nil) {
return RootLists.count;
}
if ([item isKindOfClass:[NSDictionary class]]) {
reloadCheck=true;
return [[item objectForKey:@"children"] count];
}
return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item{

if (item == nil){
return [RootLists objectAtIndex:index];
}
if ([item isKindOfClass:[NSDictionary class]]) {
return [[item objectForKey:@"children"] objectAtIndex:index];
}
return nil;
}


-(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
NSView *rowView;
rowView=[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[rowView setWantsLayer:YES];
NSTextField *textField;
[textField setMaximumNumberOfLines:1];
[textField setStringValue:[item valueForKey:@"Name"]];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[rowView addSubview:textField];
return rowView;
}



- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item{
NSMutableArray *getchildrenlist=[database GetData:[item valueForKey:@"id"]];
if (getchildrenlist.count>0) {
//If children are already present then return 1
return 1;
}
else
{
//If children are not present then hit API, get children online and then reload the view with children
dispatch_group_t DispatchGroup = dispatch_group_create();
dispatch_group_enter(DispatchGroup);
[self ExpandDataApi:1 FolderId:[item valueForKey:@"id"] DispatchGroup:DispatchGroup];
dispatch_group_notify(DispatchGroup,dispatch_get_main_queue(),^{
[self reloadData:item];
[self->_Outline_View reloadData];
});
return 1;
}

}


Now the issue is: the table reloads after each click, but never expands it with new children added to the row. Instead, it collapses all items. But after it is clicked again (same item clicked twice), the item expands correctly with new children.
What I want is: reload table and expand that row with its new children after getting new values.










share|improve this question




















  • 1





    If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

    – Willeke
    Nov 20 '18 at 14:43











  • i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

    – user10678697
    Nov 21 '18 at 6:46











  • You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

    – Willeke
    Nov 21 '18 at 16:09











  • Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

    – user10678697
    Nov 22 '18 at 11:03











  • I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

    – Willeke
    Nov 23 '18 at 0:42
















0















I am new in objective c. And I have been looking for examples/answer that describes the outline view expansion of items. Now what I am trying to do is, mark all items as expandable. Now when the user clicks to expand the item, it calls the API, inserts its children if any, and then reload the table view. The Code is given below:



 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item{
//initially make all items expandable to check and load data later on
return YES;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item{
if (item == nil) {
return RootLists.count;
}
if ([item isKindOfClass:[NSDictionary class]]) {
reloadCheck=true;
return [[item objectForKey:@"children"] count];
}
return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item{

if (item == nil){
return [RootLists objectAtIndex:index];
}
if ([item isKindOfClass:[NSDictionary class]]) {
return [[item objectForKey:@"children"] objectAtIndex:index];
}
return nil;
}


-(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
NSView *rowView;
rowView=[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[rowView setWantsLayer:YES];
NSTextField *textField;
[textField setMaximumNumberOfLines:1];
[textField setStringValue:[item valueForKey:@"Name"]];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[rowView addSubview:textField];
return rowView;
}



- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item{
NSMutableArray *getchildrenlist=[database GetData:[item valueForKey:@"id"]];
if (getchildrenlist.count>0) {
//If children are already present then return 1
return 1;
}
else
{
//If children are not present then hit API, get children online and then reload the view with children
dispatch_group_t DispatchGroup = dispatch_group_create();
dispatch_group_enter(DispatchGroup);
[self ExpandDataApi:1 FolderId:[item valueForKey:@"id"] DispatchGroup:DispatchGroup];
dispatch_group_notify(DispatchGroup,dispatch_get_main_queue(),^{
[self reloadData:item];
[self->_Outline_View reloadData];
});
return 1;
}

}


Now the issue is: the table reloads after each click, but never expands it with new children added to the row. Instead, it collapses all items. But after it is clicked again (same item clicked twice), the item expands correctly with new children.
What I want is: reload table and expand that row with its new children after getting new values.










share|improve this question




















  • 1





    If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

    – Willeke
    Nov 20 '18 at 14:43











  • i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

    – user10678697
    Nov 21 '18 at 6:46











  • You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

    – Willeke
    Nov 21 '18 at 16:09











  • Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

    – user10678697
    Nov 22 '18 at 11:03











  • I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

    – Willeke
    Nov 23 '18 at 0:42














0












0








0








I am new in objective c. And I have been looking for examples/answer that describes the outline view expansion of items. Now what I am trying to do is, mark all items as expandable. Now when the user clicks to expand the item, it calls the API, inserts its children if any, and then reload the table view. The Code is given below:



 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item{
//initially make all items expandable to check and load data later on
return YES;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item{
if (item == nil) {
return RootLists.count;
}
if ([item isKindOfClass:[NSDictionary class]]) {
reloadCheck=true;
return [[item objectForKey:@"children"] count];
}
return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item{

if (item == nil){
return [RootLists objectAtIndex:index];
}
if ([item isKindOfClass:[NSDictionary class]]) {
return [[item objectForKey:@"children"] objectAtIndex:index];
}
return nil;
}


-(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
NSView *rowView;
rowView=[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[rowView setWantsLayer:YES];
NSTextField *textField;
[textField setMaximumNumberOfLines:1];
[textField setStringValue:[item valueForKey:@"Name"]];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[rowView addSubview:textField];
return rowView;
}



- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item{
NSMutableArray *getchildrenlist=[database GetData:[item valueForKey:@"id"]];
if (getchildrenlist.count>0) {
//If children are already present then return 1
return 1;
}
else
{
//If children are not present then hit API, get children online and then reload the view with children
dispatch_group_t DispatchGroup = dispatch_group_create();
dispatch_group_enter(DispatchGroup);
[self ExpandDataApi:1 FolderId:[item valueForKey:@"id"] DispatchGroup:DispatchGroup];
dispatch_group_notify(DispatchGroup,dispatch_get_main_queue(),^{
[self reloadData:item];
[self->_Outline_View reloadData];
});
return 1;
}

}


Now the issue is: the table reloads after each click, but never expands it with new children added to the row. Instead, it collapses all items. But after it is clicked again (same item clicked twice), the item expands correctly with new children.
What I want is: reload table and expand that row with its new children after getting new values.










share|improve this question
















I am new in objective c. And I have been looking for examples/answer that describes the outline view expansion of items. Now what I am trying to do is, mark all items as expandable. Now when the user clicks to expand the item, it calls the API, inserts its children if any, and then reload the table view. The Code is given below:



 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item{
//initially make all items expandable to check and load data later on
return YES;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item{
if (item == nil) {
return RootLists.count;
}
if ([item isKindOfClass:[NSDictionary class]]) {
reloadCheck=true;
return [[item objectForKey:@"children"] count];
}
return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item{

if (item == nil){
return [RootLists objectAtIndex:index];
}
if ([item isKindOfClass:[NSDictionary class]]) {
return [[item objectForKey:@"children"] objectAtIndex:index];
}
return nil;
}


-(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
NSView *rowView;
rowView=[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[rowView setWantsLayer:YES];
NSTextField *textField;
[textField setMaximumNumberOfLines:1];
[textField setStringValue:[item valueForKey:@"Name"]];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[rowView addSubview:textField];
return rowView;
}



- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item{
NSMutableArray *getchildrenlist=[database GetData:[item valueForKey:@"id"]];
if (getchildrenlist.count>0) {
//If children are already present then return 1
return 1;
}
else
{
//If children are not present then hit API, get children online and then reload the view with children
dispatch_group_t DispatchGroup = dispatch_group_create();
dispatch_group_enter(DispatchGroup);
[self ExpandDataApi:1 FolderId:[item valueForKey:@"id"] DispatchGroup:DispatchGroup];
dispatch_group_notify(DispatchGroup,dispatch_get_main_queue(),^{
[self reloadData:item];
[self->_Outline_View reloadData];
});
return 1;
}

}


Now the issue is: the table reloads after each click, but never expands it with new children added to the row. Instead, it collapses all items. But after it is clicked again (same item clicked twice), the item expands correctly with new children.
What I want is: reload table and expand that row with its new children after getting new values.







objective-c macos cocoa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 10:45







user10678697

















asked Nov 20 '18 at 8:32









user10678697user10678697

11




11








  • 1





    If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

    – Willeke
    Nov 20 '18 at 14:43











  • i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

    – user10678697
    Nov 21 '18 at 6:46











  • You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

    – Willeke
    Nov 21 '18 at 16:09











  • Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

    – user10678697
    Nov 22 '18 at 11:03











  • I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

    – Willeke
    Nov 23 '18 at 0:42














  • 1





    If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

    – Willeke
    Nov 20 '18 at 14:43











  • i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

    – user10678697
    Nov 21 '18 at 6:46











  • You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

    – Willeke
    Nov 21 '18 at 16:09











  • Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

    – user10678697
    Nov 22 '18 at 11:03











  • I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

    – Willeke
    Nov 23 '18 at 0:42








1




1





If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

– Willeke
Nov 20 '18 at 14:43





If you don't want to restart with collapsed items then don't call reloadData. You can expand that row with expandItem:.

– Willeke
Nov 20 '18 at 14:43













i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

– user10678697
Nov 21 '18 at 6:46





i believe reloadData refreshes the table. If i just use expanditem, it will only expand item and not add up new items to the row. i need to either reload that specific row or item but i dont know how to do that.

– user10678697
Nov 21 '18 at 6:46













You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

– Willeke
Nov 21 '18 at 16:09





You can reload a specific row with reloadItem: or reloadItem:reloadChildren:. See NSOutlineView.

– Willeke
Nov 21 '18 at 16:09













Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

– user10678697
Nov 22 '18 at 11:03





Tried using reloaditem: , but it doesn't reload the children. It will only expand item and not add up new items to the row. I dont know where i am doing wrong in this.

– user10678697
Nov 22 '18 at 11:03













I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

– Willeke
Nov 23 '18 at 0:42





I tried to reproduce the issue and it looks like NSOutlineView is caching the items and gets out of sync.

– Willeke
Nov 23 '18 at 0:42












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388982%2fhow-to-update-row-values-and-children-when-row-of-outline-view-is-expanded-each%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388982%2fhow-to-update-row-values-and-children-when-row-of-outline-view-is-expanded-each%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory