2012-11-11 37 views
5

मैं कोको के लिए नया हूं और मैं निराश हो रहा हूं, मैंने एनएसटीबल व्यू सेल में एनएसवी व्यू को जोड़ने का तरीका जानने के लिए लगभग आधे दिन बिताए हैं, लेकिन मुझे कोई नहीं मिला है अच्छा गाइड मुझे ऐसा मैं प्राप्त करने के लिए चाहते हैं क्या मदद कर सकते हैं, हो सकता है किसी को मैं क्या कोशिश की है पर एक नजर है और मुझे बताओ कि क्यों यह काम नहीं कर रहा और मैं इसे कैसे काम करने के लिए मिल सकता है कर सकते हैं ...एनएसटीबल व्यू सेल में कोको एनएसवी व्यू

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ 
NSTableCellView *view = [tableView makeViewWithIdentifier:@"MyView" owner:self]; 
NSTextField *textfield = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0, 100, 30)]; 
[textfield setStringValue:predictate_search[row]]; 
[textfield setBackgroundColor:[NSColor redColor]]; 
[view addSubview:textfield]; 
[view setNeedsDisplay:YES]; 
return view; 
} 

मैं जो हासिल करना चाहता हूं वह एक दूसरे के ऊपर दो एनएसटीक्स्टफिल्ड्स और टेबल सेल को कस्टम पृष्ठभूमि रखने के लिए है। ऊपर मुझे सिर्फ एक NSTextField काम करने के लिए प्राप्त करने के लिए कोशिश कर रहा है, लेकिन कोई भाग्य के साथ ...

NSTableView प्रोग्राम के रूप में बनाया जा रहा है:

NSScrollView *scrollView = [[NSScrollView alloc]initWithFrame:bg]; 
    [scrollView setHasVerticalScroller:YES]; 
    [self addSubview:scrollView]; 

    search_results = [[NSTableView alloc]initWithFrame:bg]; 
    NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"id"]; 
    [[column headerCell] setStringValue:@"Cities"]; 
    [column setWidth:1000.0]; 

    [search_results addTableColumn:column]; 
    [search_results setDelegate:(id)self]; 
    [search_results setDataSource:(id)self]; 
    [search_results reloadData]; 

    [scrollView setDocumentView:search_results]; 

मैं थोड़ा क्या makeViewWithIdentifier: के लिए डाल करने के लिए उलझन में हूँ, मैंने NSTableViews पर WWDC 2011 वीडियो देखा है लेकिन मुझे अभी भी वास्तव में यकीन नहीं है।

आप की आवश्यकता होती है और अधिक जानकारी के लिए कहें

धन्यवाद

संपादित पहले उत्तर के बाद:

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ 
NSTableCellView *view = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:self]; 
if(view == nil){ 
    NSTableCellView *view = [[NSTableCellView alloc]initWithFrame:[tableView frame]]; 
    view.identifier = [tableColumn identifier]; 
} 
NSTextField *textfield = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0, 100, 30)]; 
[textfield setStringValue:predictate_search[row]]; 
[textfield setBackgroundColor:[NSColor redColor]]; 
[view addSubview:textfield]; 
[view setNeedsDisplay:YES]; 
return view; 

}

हालांकि यह अभी भी काम नहीं कर रहा?

उत्तर

1

अपने विधि देता है कि सेल अगर यह dequeable नहीं है सेल करना चाहिए (क्योंकि कोई नहीं है)

// There is no existing cell to reuse so we will create a new one 
if (result == nil) { 

    // create the new NSTextField with a frame of the {0,0} with the width of the table 
    // note that the height of the frame is not really relevant, the row-height will modify the height 
    // the new text field is then returned as an autoreleased object 
    result = [[[NSTextField alloc] initWithFrame:...] autorelease]; 

    // the identifier of the NSTextField instance is set to MyView. This 
    // allows it to be re-used 
    result.identifier = @"MyView"; 
    } 
+0

मैंने इसे जोड़ा, लेकिन यह अभी भी काम नहीं करता है ... –

+0

बस जांच रहा है ... आपने अन्य तरीकों को लागू किया है? :: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTableDataSource_Protocol/Reference/Reference.html –

+0

मैंने '- (एनएसआईएनटेगर) संख्या लागू की है OfRowsInTableView: (NSTableView *) aTableView' जहां तक ​​मुझे पता है कि यह केवल अनिवार्य है ... –

6

कोड के नीचे मेरी समस्या हल:

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{ 
NSView *view = [tableView makeViewWithIdentifier:@"MyView" owner:self]; 

if (view == nil) { 
    view = [[NSView alloc]initWithFrame:NSMakeRect(0, 0, 100, 30)]; 
    NSTextField *result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 25, 800, 25)]; 
    NSTextField *result2 = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 800, 25)]; 
    result.stringValue = [predictate_search objectAtIndex:row]; 
    result2.stringValue = @"UnitedKingdom"; 
    [view addSubview:result]; 
    [view addSubview:result2]; 
    [view setNeedsDisplay:YES]; 
} 

return view; 

} 

मदद के लिए धन्यवाद :)

0

ठीक है, बस इसे देखकर, मैं किसी जवाब में जोड़ने जा रहा हूं अगर कोई भविष्य में इस पर ठोकर खाए।

दृश्य कोड स्निपेट की दूसरी पंक्ति में परिभाषित किया गया है। यदि यह शून्य है, तो यह बयान में गिर जाता है और दृश्य फिर से परिभाषित किया जाता है। इन कथन से निकलने वाला दृश्य गायब हो जाता है क्योंकि इसे ब्रैकेट के दायरे में परिभाषित किया गया था और जब प्रोग्राम उस दायरे को छोड़ देता है तो आपको मूल शून्य छोड़ देता है।

अब इसके साथ बहुत अधिक समस्याएं हो सकती हैं लेकिन यह चिपक जाती है। मैं इस विषय पर कुछ शोध कर रहा था और इस सवाल को पाया और स्कोपिंग समस्या देखी।