- Registriert
- 20.03.08
- Beiträge
- 476
Liebe Community!
Ich schreibe gerade an einem kleinen Programm, welches eine Textdatei Zeilenweise einliest und den Inhalt jeweils in ein Multiline Label schreibt.
Das Funktioniert folgendermaßen ganz gut:
Am Anfang jeder Zeile steht testhalber das Wort "Zeilenanfang"
Über eine weitere Funktion füge ich der Datei eine Zeile hinzu.
Automatisch kommt das Schlüsselwort "Zeilenanfang" vorne mit dran:
Nach dieser Funktion wird der Code oben noch mal ausgeführt, um ein Update des Textfeldes zu machen.
Das hab ich jetzt einfach weg gelassen.
Nun zu meiner eigentlichen Frage:
Ich möchte, dass an der Seite neben jeder Zeile ein kleiner Button hinzugefügt wird.
Mit diesem Button möchte ich die jeweilige Zeile löschen.
Sprich ich muss für jeden Eintrag in der While-Schleife sagen: "Füge Knopf hinzu mit dem Befehl 'löschen(Zeileninhalt)' "
Und dann soll die Funktion löschen(variable) ausgeführt werden und immer fragen:
Kann mir jemand von euch dabei helfen?
Irgend eine Anregung oder Idee?
Vielen Dank & liebe Grüße
…
Ich schreibe gerade an einem kleinen Programm, welches eine Textdatei Zeilenweise einliest und den Inhalt jeweils in ein Multiline Label schreibt.
Das Funktioniert folgendermaßen ganz gut:
Am Anfang jeder Zeile steht testhalber das Wort "Zeilenanfang"
Code:
[COLOR=#3F217C][COLOR=#000000][[/COLOR][COLOR=#4b8186]label[/COLOR][COLOR=#000000] [/COLOR]setStringValue[COLOR=#000000]:[/COLOR][COLOR=#d62b24]@""[/COLOR][COLOR=#000000]];[/COLOR][/COLOR][COLOR=#7340a3][COLOR=#000000] [/COLOR]NSString[COLOR=#000000] *tmp;[/COLOR][/COLOR]
[COLOR=#7340a3]NSArray[/COLOR] *lines;
[COLOR=#d62b24][COLOR=#000000] lines = [[[/COLOR][COLOR=#7340a3]NSString[/COLOR][COLOR=#000000] [/COLOR][COLOR=#3f217c]stringWithContentsOfFile[/COLOR][COLOR=#000000]:[/COLOR]@"~/test.txt"[COLOR=#000000]] [/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [/COLOR]componentsSeparatedByString[COLOR=#000000]:[/COLOR][COLOR=#d62b24]@"\n"[/COLOR][COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#7340a3]NSEnumerator[/COLOR] *nse = [lines [COLOR=#3f217c]objectEnumerator[/COLOR]];
[COLOR=#bf2e9d]while[/COLOR](tmp = [nse [COLOR=#3f217c]nextObject[/COLOR]]) {
[COLOR=#3f217c][COLOR=#000000] [/COLOR][COLOR=#bf2e9d]if[/COLOR][COLOR=#000000] ([tmp [/COLOR]rangeOfString[COLOR=#000000]:[/COLOR][COLOR=#d62b24]@"Zeilenanfang"[/COLOR][COLOR=#000000]].[/COLOR][COLOR=#7340a3]location[/COLOR][COLOR=#000000] != [/COLOR]NSNotFound[COLOR=#000000]) {[/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [/COLOR][COLOR=#000000][[/COLOR][COLOR=#4b8186]label[/COLOR][COLOR=#000000] [/COLOR]setStringValue[COLOR=#000000]:[[[/COLOR][COLOR=#4b8186]label[/COLOR][COLOR=#000000] [/COLOR]stringValue[COLOR=#000000]] [/COLOR]stringByAppendingString[COLOR=#000000]:[/COLOR][COLOR=#d62b24]@"\n"[/COLOR][COLOR=#000000]]];[/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [[/COLOR][COLOR=#4b8186]label[/COLOR][COLOR=#000000] [/COLOR]setStringValue[COLOR=#000000]:[[[/COLOR][COLOR=#4b8186]label[/COLOR][COLOR=#000000] [/COLOR]stringValue[COLOR=#000000]] [/COLOR]stringByAppendingString[COLOR=#000000]:tmp]];[/COLOR][/COLOR]
}
}
Über eine weitere Funktion füge ich der Datei eine Zeile hinzu.
Automatisch kommt das Schlüsselwort "Zeilenanfang" vorne mit dran:
Code:
[COLOR=#D62B24][COLOR=#7340a3]NSString[/COLOR][COLOR=#000000] *path = [/COLOR]@"~/test.txt"[COLOR=#000000];[/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [/COLOR][COLOR=#7340a3]NSData[/COLOR][COLOR=#000000] *dataR = [[[/COLOR][COLOR=#d62b24]@"\nZeilenanfang "[/COLOR][COLOR=#000000] [/COLOR]stringByAppendingString[COLOR=#000000]:[[/COLOR][COLOR=#4b8186]text[/COLOR][COLOR=#000000] [/COLOR]stringValue[COLOR=#000000]]] [/COLOR]dataUsingEncoding[COLOR=#000000]:[/COLOR]NSUTF8StringEncoding[COLOR=#000000]];[/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [/COLOR][COLOR=#7340a3]NSFileHandle[/COLOR][COLOR=#000000]* fh = [[/COLOR][COLOR=#7340a3]NSFileHandle[/COLOR][COLOR=#000000] [/COLOR]fileHandleForWritingAtPath[COLOR=#000000]:path];[/COLOR][/COLOR]
[COLOR=#3f217c][COLOR=#000000] [fh [/COLOR]seekToEndOfFile[COLOR=#000000]];[/COLOR][/COLOR]
[fh [COLOR=#3f217c]writeData[/COLOR]:dataR];
[COLOR=#3F217C][COLOR=#000000] [fh [/COLOR]closeFile[COLOR=#000000]];[/COLOR][/COLOR]
Das hab ich jetzt einfach weg gelassen.
Nun zu meiner eigentlichen Frage:
Ich möchte, dass an der Seite neben jeder Zeile ein kleiner Button hinzugefügt wird.
Mit diesem Button möchte ich die jeweilige Zeile löschen.
Sprich ich muss für jeden Eintrag in der While-Schleife sagen: "Füge Knopf hinzu mit dem Befehl 'löschen(Zeileninhalt)' "
Und dann soll die Funktion löschen(variable) ausgeführt werden und immer fragen:
Code:
[COLOR=#BF2E9D]while[/COLOR](tmp = [nse [COLOR=#3F217C]nextObject[/COLOR]]) {[COLOR=#3F217C][COLOR=#000000] [/COLOR][COLOR=#BF2E9D]if[/COLOR][COLOR=#000000] ([tmp [/COLOR]rangeOfString[COLOR=#000000]:[/COLOR][I][COLOR=#D62B24]variable[/COLOR][/I][COLOR=#000000]].[/COLOR][COLOR=#7340A3]location[/COLOR][COLOR=#000000] != [/COLOR]NSNotFound[COLOR=#000000]) {[/COLOR][/COLOR]
[COLOR=#3F217C][COLOR=#000000] [I]Zeile weg lassen / löschen[/I][/COLOR][/COLOR]
}
}
Kann mir jemand von euch dabei helfen?
Irgend eine Anregung oder Idee?
Vielen Dank & liebe Grüße
…