Custom Table View Cells with TextField Problems - ios-simulator

HI, So here's what I'm trying to do. I have a table View and I'm using Custom Table View Cells with text Fields. Basically you enter Text in the fields and it saves it to a managed object context. I have set up the Table View thusly;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//static NSString *CustCell=#"CustomCell";
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell== nil) {
cell= [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.row) {
case 0:
cell.primaryLabel.text = #"Name";
cell.mainTextField.text=product.prodName;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 1:
cell.primaryLabel.text = #"Store";
cell.mainTextField.text=product.store;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 2:
cell.primaryLabel.text=#"Amount";
cell.mainTextField.text=product.amount;
cell.mainTextField.keyboardType=UIKeyboardTypeNumberPad;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 3:
cell.primaryLabel.text=#"Measure";
cell.detailLabel.text=product.measure;
cell.mainTextField.hidden=YES;
break;
case 4:
cell.primaryLabel.text=#"Package";
cell.detailLabel.text=product.container;
cell.mainTextField.hidden=YES;
break;
case 5:
cell.primaryLabel.text=#"Aisle";
cell.detailLabel.text=product.aisle;
cell.mainTextField.hidden=YES;
break;
case 6:
cell.primaryLabel.text=#"Note";
cell.mainTextField.text=product.note;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
default:
break;
}
return cell;
}
So here's my issue. At runtime I can enter text in cells 1-3 no problem it saves and everything's happy. But if I enter anything in cell 6 it returns Null for cell.nameTextField.text and I don't know why.
What I've done.
1. I tried creating a single instance cell in the nib and placing it in that cell.
2. I tried Setting it to index.row 0 of a new section.
3. Tried adding a text field to the content view of a standard cell at that index.
4. commented out the save method for that cell.
5. tried creating a separate textField and setting the cell.mainTextFiled to Hidden.
6. Tried creating the table View Programmatically without using the nib.
7. It all worked when I used single instance cells from the nib for all four of these cells. If that's the answer, so be it. But Custom Table View Cells created programmatically are so much more concise and elegant.
To add insult to insanity If I move that cell to an index of 5 or below everything works great. Any index over 5 and it blows up.
I have scoured the web and the dev docs as well as the 4 iPhone Dev books that I have.
I am here because I have exhausted what I can do. I'm sure it's something dumb that I'm missing but I'm flummoxed. Any help would be appreciated.
The ultimate goal is to have have notes in a second section with more room to write.
Yes I know there are other ways to do this but it seems that this should work and I would love to know why it doesn't.
Oh, I should mention that I have only been using the iPhone simulator. I have not tried running on a phone.
Thanks.

OK, I'm an idiot. After posting this I found the answer (of course!) Simply put. When the cell with the text field scrolls out of view it dequeues the cell. When the cell reappears it gets re-instantiated with a shiny clean text field. So now I'm looking at ways to overcome this. Arrays come to mind. I'll post what I find. If anyone has ideas about this problem I'd love to hear them.

Related

Image won't display when using session in .NET

I am working with a session and I want to display image when choosing it from a gridview, so what I have two gridviews the first contain the rows from the database the second should contain the rows chosen from the first one the issue that I have is the first display image with no problem but the second won't show up any.
This is my code for the first one
foreach (CONTENT c in ls)
{
string ext = Helper_GetExtensionFromMimeType(c.MimeType);
c.TmpFilename = string.Format("~/Images/Contents/Content-{0}{1}", c.ContentID, ext);
}
gridview1.DataSource = ls;
gridview1.DataBind();
The code for the second one is (the session name is panier)
CONTENT dummy;
dummy = new CONTENT();
dummy.TmpFilename = Server.MapPath(string.Format("~/Images/Contents/Content-{0}{1}",
c.ContentID, ext));
panier.Add(dummy);
gridview2.DataSource = panier;
gridview2.DataBind();
It will be hard to determine what the issue exactly is without seeing your view code.
Anyway, make sure the image indeed exists in the generated location.
Place a breakpoint after the line dummy.TmpFilename and ensure the link is indeed formatted with the correct c.ContentID and ext, then copy the link to the browser making sure the image exists.
i found a solution to the probleme and here it is if anyone is interested
i replace
dummy.TmpFilename = Server.MapPath(string.Format("~/Images/Contents/Content-{0}{1}",c.ContentID, ext));
with
dummy.TmpFilename =string.Format("~/Images/Contents/Content-{0}{1}",c.ContentID, ext);

setObjectValue:nil not called to deleted NSTableCellView

I'm using a View Based NSTableView and binding to display content of my objects.
When I delete one of them, the tableView reflect the change, by removing the cell for this object.
The problem is that the NSTableCellView doesn't receive the setObjectValue: with nil or another object, and so the object referenceCount is not decremented, and my object never release.
Is there a way to override the tableView to force calling setObjectValue: when it cache deletedRows?
Thanks for your help.
I just found the solution right here.
https://devforums.apple.com/message/575883#575883
Just in case the link fail, the solution is to set it manually, in the following method
- (void)tableView:(NSTableView *)tableView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger)row NS_AVAILABLE_MAC(10_7);
{
for (NSInteger columnIndex = 0; columnIndex < [rowView numberOfColumns]; columnIndex++) {
[[rowView viewAtColumn:columnIndex] setObjectValue:nil];
}
}

Is there a way to access ALAssets information outside of resultBlock?

Okay so I have my ImagePicker all setup and the ALAssetLibrary setup to get the Picture and Title (if it exists for existing pictures or generic text for a new picture) but now I'm trying to figure out if there's a way I can access this information outside of the block call from the assetForURL method. So here's my code just so I can show what's happening (this is in the viewDidLoad method of a screen that is displayed after a picture selection is made)
__block NSString *documentName;
__block UIImage *docImage;
NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
{
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
//Get Image
CGImageRef iref = [imageRep fullResolutionImage];
//If image is null then it's a new picture from Camera
if (iref == NULL) {
docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
documentName = #"New Picture";
}
else {
docImage = [UIImage imageWithCGImage:iref];
documentName = [imageRep filename];
}
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
[imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];
Now I want to be able to use the two variables (documentName and docImage) elsewhere in this ViewController (for example if someone wants to change the name of the document before they save it I want to be able to revert back to the default name) but I can't seem to figure out what I need to do so these variables can be used later. Don't know if this makes much sense or not, so if I need to clarify anything else let me know.
Okay so I figured out that the problem wasn't with the code but with my logic on how I was using it. I was trying to do this on the Modal View that was presented after an image was selected instead of just doing this in the ImagePicker screen and then calling the Modal window inside of the result block code.

Please explain me how to control a Table View in Cocoa?

I search Google to find a good answer but the most tutorials are shown in previous Xcode Versions...
Also, I don't want to drag-n-drop cells from the Interface Builder, but to control the Table View programmatically (from an NSObject subclass file).
What I currently do is this: 1. Create a file named tableController.h that is a subclass of NSObject.
2. I create an NSObject Object in my Nib File (and set it as a subclass of tableController).
3. I drag a Table View to my window.
4. I CTRL+Drag from the Table View to my tableController.h so to create the outlet "tableView"
5. I create these functions in the interface file:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV;
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row;
6. I implement the functions like this:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV{
return 5;
}
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row{
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}
Then I CTRL+Drag from the Object in the Interface Builder to the Table View to set the dataSource and to set it as delegate.
When I build and Run the App it shows that it has created the 5 Rows but in every cell in every column it says "Table View Cell".
Any help would be appreciated....
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row is wrong.. i'm not sure how it compiles, to be honest (unless there was an error copy/pasting it). the method should look like:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}

Qt: two actions in menu (with the same text)

I create a menu dynamically. I add several checkable actions into one menu. Sometimes actions may have the same text that user sees. It's up to user (actually user adds commands into menu).
The problem is in this case clicking works wrong. If I click on the first action (from 2 with the same texts) everything is good but if I click on the second one, both actions are selected. I don't understand why. The code where actions have been created is here:
for (int i = 0; i< currentList.size(); i++)
{
QString lanKey = currentList.at(i)->Language->toString();
QAction* lanAction = new QAction(this);
QString name ="action_" + currentList.at(i)->Id->toString();
lanAction->setObjectName(name);
lanAction->setText(lanKey);
lanAction->setCheckable(true);
lanAction->setData(i);
connect(lanAction, SIGNAL(triggered(bool)), this, SLOT(ShowSomething(bool)));
ui->menuMy->addAction(lanAction);
}
Here, lanKey is language that may be the same for different actions. Anyway click on the specific action should lead only to checking of this action. What's wrong?
The slot is here:
void VMainWindow::ShowSomething(bool IsTriggered)
{
QAction* senderAction = (QAction*)sender();
int listIndex = senderAction->data().toInt();
if (IsTriggered)
{
CreateEditor(subtitles, listIndex);
}
else
{
//hide this editor
QString name = "editor" + editorsList->Id->toString();
QDockWidget* editorDock = this->findChild<QDockWidget*>(name);
if (editorDock != 0)
{
this->removeDockWidget(editorDock);
this->setLayout(layout());
}
}
}
Thanks
The source of problem is found: it turned out that the slot finds the checked action wrong - by text, not by id.
I can't find a logical issue in the code you posted so far. Here are a couple of options which I would try in order to resolve this problem:
Limit the users possibilities when adding items to a menu so that he can't add two items with the same name.
Add qDebug() output to ShowSomething to see if there is a problem with signals&slots. For example, if the slot gets called once for the first item but twice for the second item there is a problem there.
Debug into CreateEditor step-by-step.
As the problem seems to appear only for actions with a similar name, you should make sure that you never make a lookup of an action (or something related) by its text() but rather by its data() or objectName() (assuming that currentList.at(i)->Id will always be unique)

Resources