Manage tableview cell after reloading cell from tableview, Data in textfield is not getting clear












1














initial point App start screenshot



initial point App start screenshot



the second screenshot when I add new cell



the second screenshot when I add new cell



after adding third and fourth cell



after adding third and fourth cell



after fifth it reload the cell again



after fifth it reload the cell again



UITableviewcell containing text field. Each cell text field should contain different data. when user enter.



My issue is when table view load with a first cell(Individual 1). when I add next cell(Individual 2) and continue adding cell(Individual 3, Individual 4) as shown in the screenshot. when I add the cell(Individual 5) the cell(Individual 5) with text field reload the same data of a cell of (Individual 1). The cell of the individual 5 text field should be empty.



But I cannot manage the cell and clear the text field when they reload the cell?



I am new in swift...
Please HELP!!



Thx in advances...



class ViewController:UIViewController,UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var addmore: UIButton!
var ar = ["Individual 1"]

@IBOutlet weak var tableview: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ar.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableview.dequeueReusableCell(withIdentifier: "cell") as! TableTVC
cell.indivuallbl.text! = ar[indexPath.row ]
return cell
}



func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 240.5
}

@IBAction func deleterow(_ sender: Any) {

let point = (sender as AnyObject).convert(CGPoint.zero, to: tableview)
guard let indexPath = tableview.indexPathForRow(at: point) else {
return
}
ar.remove(at: indexPath.row)
print(ar.count)



}


override func viewDidLoad() {
super.viewDidLoad()

NSLog("a", 1)
addmore.layer.cornerRadius = 5


}




@IBAction func addmore(_ sender: Any) {


ar.insert("Individual (ar.count + 1 )", at: ar.count)
print(ar.count)
let myIndexPath = IndexPath(row: ar.count-1 , section: 0)
tableview.insertRows(at: [myIndexPath], with: .bottom)


}









share|improve this question
























  • It would be great if you add code related to Add New cell.
    – Kuldeep
    Nov 13 '18 at 9:41






  • 1




    This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
    – vadian
    Nov 13 '18 at 9:43












  • I have added the code above @Kuldeep
    – Abhi
    Nov 13 '18 at 10:04












  • Thank you @vadian
    – Abhi
    Nov 13 '18 at 10:05
















1














initial point App start screenshot



initial point App start screenshot



the second screenshot when I add new cell



the second screenshot when I add new cell



after adding third and fourth cell



after adding third and fourth cell



after fifth it reload the cell again



after fifth it reload the cell again



UITableviewcell containing text field. Each cell text field should contain different data. when user enter.



My issue is when table view load with a first cell(Individual 1). when I add next cell(Individual 2) and continue adding cell(Individual 3, Individual 4) as shown in the screenshot. when I add the cell(Individual 5) the cell(Individual 5) with text field reload the same data of a cell of (Individual 1). The cell of the individual 5 text field should be empty.



But I cannot manage the cell and clear the text field when they reload the cell?



I am new in swift...
Please HELP!!



Thx in advances...



class ViewController:UIViewController,UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var addmore: UIButton!
var ar = ["Individual 1"]

@IBOutlet weak var tableview: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ar.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableview.dequeueReusableCell(withIdentifier: "cell") as! TableTVC
cell.indivuallbl.text! = ar[indexPath.row ]
return cell
}



func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 240.5
}

@IBAction func deleterow(_ sender: Any) {

let point = (sender as AnyObject).convert(CGPoint.zero, to: tableview)
guard let indexPath = tableview.indexPathForRow(at: point) else {
return
}
ar.remove(at: indexPath.row)
print(ar.count)



}


override func viewDidLoad() {
super.viewDidLoad()

NSLog("a", 1)
addmore.layer.cornerRadius = 5


}




@IBAction func addmore(_ sender: Any) {


ar.insert("Individual (ar.count + 1 )", at: ar.count)
print(ar.count)
let myIndexPath = IndexPath(row: ar.count-1 , section: 0)
tableview.insertRows(at: [myIndexPath], with: .bottom)


}









share|improve this question
























  • It would be great if you add code related to Add New cell.
    – Kuldeep
    Nov 13 '18 at 9:41






  • 1




    This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
    – vadian
    Nov 13 '18 at 9:43












  • I have added the code above @Kuldeep
    – Abhi
    Nov 13 '18 at 10:04












  • Thank you @vadian
    – Abhi
    Nov 13 '18 at 10:05














1












1








1







initial point App start screenshot



initial point App start screenshot



the second screenshot when I add new cell



the second screenshot when I add new cell



after adding third and fourth cell



after adding third and fourth cell



after fifth it reload the cell again



after fifth it reload the cell again



UITableviewcell containing text field. Each cell text field should contain different data. when user enter.



My issue is when table view load with a first cell(Individual 1). when I add next cell(Individual 2) and continue adding cell(Individual 3, Individual 4) as shown in the screenshot. when I add the cell(Individual 5) the cell(Individual 5) with text field reload the same data of a cell of (Individual 1). The cell of the individual 5 text field should be empty.



But I cannot manage the cell and clear the text field when they reload the cell?



I am new in swift...
Please HELP!!



Thx in advances...



class ViewController:UIViewController,UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var addmore: UIButton!
var ar = ["Individual 1"]

@IBOutlet weak var tableview: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ar.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableview.dequeueReusableCell(withIdentifier: "cell") as! TableTVC
cell.indivuallbl.text! = ar[indexPath.row ]
return cell
}



func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 240.5
}

@IBAction func deleterow(_ sender: Any) {

let point = (sender as AnyObject).convert(CGPoint.zero, to: tableview)
guard let indexPath = tableview.indexPathForRow(at: point) else {
return
}
ar.remove(at: indexPath.row)
print(ar.count)



}


override func viewDidLoad() {
super.viewDidLoad()

NSLog("a", 1)
addmore.layer.cornerRadius = 5


}




@IBAction func addmore(_ sender: Any) {


ar.insert("Individual (ar.count + 1 )", at: ar.count)
print(ar.count)
let myIndexPath = IndexPath(row: ar.count-1 , section: 0)
tableview.insertRows(at: [myIndexPath], with: .bottom)


}









share|improve this question















initial point App start screenshot



initial point App start screenshot



the second screenshot when I add new cell



the second screenshot when I add new cell



after adding third and fourth cell



after adding third and fourth cell



after fifth it reload the cell again



after fifth it reload the cell again



UITableviewcell containing text field. Each cell text field should contain different data. when user enter.



My issue is when table view load with a first cell(Individual 1). when I add next cell(Individual 2) and continue adding cell(Individual 3, Individual 4) as shown in the screenshot. when I add the cell(Individual 5) the cell(Individual 5) with text field reload the same data of a cell of (Individual 1). The cell of the individual 5 text field should be empty.



But I cannot manage the cell and clear the text field when they reload the cell?



I am new in swift...
Please HELP!!



Thx in advances...



class ViewController:UIViewController,UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var addmore: UIButton!
var ar = ["Individual 1"]

@IBOutlet weak var tableview: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ar.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableview.dequeueReusableCell(withIdentifier: "cell") as! TableTVC
cell.indivuallbl.text! = ar[indexPath.row ]
return cell
}



func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 240.5
}

@IBAction func deleterow(_ sender: Any) {

let point = (sender as AnyObject).convert(CGPoint.zero, to: tableview)
guard let indexPath = tableview.indexPathForRow(at: point) else {
return
}
ar.remove(at: indexPath.row)
print(ar.count)



}


override func viewDidLoad() {
super.viewDidLoad()

NSLog("a", 1)
addmore.layer.cornerRadius = 5


}




@IBAction func addmore(_ sender: Any) {


ar.insert("Individual (ar.count + 1 )", at: ar.count)
print(ar.count)
let myIndexPath = IndexPath(row: ar.count-1 , section: 0)
tableview.insertRows(at: [myIndexPath], with: .bottom)


}






ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 10:03







Abhi

















asked Nov 13 '18 at 9:40









AbhiAbhi

84




84












  • It would be great if you add code related to Add New cell.
    – Kuldeep
    Nov 13 '18 at 9:41






  • 1




    This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
    – vadian
    Nov 13 '18 at 9:43












  • I have added the code above @Kuldeep
    – Abhi
    Nov 13 '18 at 10:04












  • Thank you @vadian
    – Abhi
    Nov 13 '18 at 10:05


















  • It would be great if you add code related to Add New cell.
    – Kuldeep
    Nov 13 '18 at 9:41






  • 1




    This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
    – vadian
    Nov 13 '18 at 9:43












  • I have added the code above @Kuldeep
    – Abhi
    Nov 13 '18 at 10:04












  • Thank you @vadian
    – Abhi
    Nov 13 '18 at 10:05
















It would be great if you add code related to Add New cell.
– Kuldeep
Nov 13 '18 at 9:41




It would be great if you add code related to Add New cell.
– Kuldeep
Nov 13 '18 at 9:41




1




1




This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
– vadian
Nov 13 '18 at 9:43






This is the standard behavior as cells are reused. You – the developer – are responsible to set all UI elements to a defined state. Show the code of cellForRow
– vadian
Nov 13 '18 at 9:43














I have added the code above @Kuldeep
– Abhi
Nov 13 '18 at 10:04






I have added the code above @Kuldeep
– Abhi
Nov 13 '18 at 10:04














Thank you @vadian
– Abhi
Nov 13 '18 at 10:05




Thank you @vadian
– Abhi
Nov 13 '18 at 10:05












1 Answer
1






active

oldest

votes


















0














TableView Cell reuse itself. Everytime it reused, prepareForReuse method is called. Override this method of your cell. Set values to nil.



Refer this link:- https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse



override func prepareForReuse() {
// Clean up all values

}





share|improve this answer





















  • override methods should be written in uitableviewcell?
    – Abhi
    Nov 13 '18 at 10:10










  • Yes. you have to override it in your custom cell.
    – Viren Malhan
    Nov 13 '18 at 10:13












  • thank you... I got the solution. It's working
    – Abhi
    Nov 13 '18 at 10:16










  • Welcome @Abhi. Upvote if you liked it.
    – Viren Malhan
    Nov 13 '18 at 10:19











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%2f53278002%2fmanage-tableview-cell-after-reloading-cell-from-tableview-data-in-textfield-is%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














TableView Cell reuse itself. Everytime it reused, prepareForReuse method is called. Override this method of your cell. Set values to nil.



Refer this link:- https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse



override func prepareForReuse() {
// Clean up all values

}





share|improve this answer





















  • override methods should be written in uitableviewcell?
    – Abhi
    Nov 13 '18 at 10:10










  • Yes. you have to override it in your custom cell.
    – Viren Malhan
    Nov 13 '18 at 10:13












  • thank you... I got the solution. It's working
    – Abhi
    Nov 13 '18 at 10:16










  • Welcome @Abhi. Upvote if you liked it.
    – Viren Malhan
    Nov 13 '18 at 10:19
















0














TableView Cell reuse itself. Everytime it reused, prepareForReuse method is called. Override this method of your cell. Set values to nil.



Refer this link:- https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse



override func prepareForReuse() {
// Clean up all values

}





share|improve this answer





















  • override methods should be written in uitableviewcell?
    – Abhi
    Nov 13 '18 at 10:10










  • Yes. you have to override it in your custom cell.
    – Viren Malhan
    Nov 13 '18 at 10:13












  • thank you... I got the solution. It's working
    – Abhi
    Nov 13 '18 at 10:16










  • Welcome @Abhi. Upvote if you liked it.
    – Viren Malhan
    Nov 13 '18 at 10:19














0












0








0






TableView Cell reuse itself. Everytime it reused, prepareForReuse method is called. Override this method of your cell. Set values to nil.



Refer this link:- https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse



override func prepareForReuse() {
// Clean up all values

}





share|improve this answer












TableView Cell reuse itself. Everytime it reused, prepareForReuse method is called. Override this method of your cell. Set values to nil.



Refer this link:- https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse



override func prepareForReuse() {
// Clean up all values

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 9:49









Viren MalhanViren Malhan

755




755












  • override methods should be written in uitableviewcell?
    – Abhi
    Nov 13 '18 at 10:10










  • Yes. you have to override it in your custom cell.
    – Viren Malhan
    Nov 13 '18 at 10:13












  • thank you... I got the solution. It's working
    – Abhi
    Nov 13 '18 at 10:16










  • Welcome @Abhi. Upvote if you liked it.
    – Viren Malhan
    Nov 13 '18 at 10:19


















  • override methods should be written in uitableviewcell?
    – Abhi
    Nov 13 '18 at 10:10










  • Yes. you have to override it in your custom cell.
    – Viren Malhan
    Nov 13 '18 at 10:13












  • thank you... I got the solution. It's working
    – Abhi
    Nov 13 '18 at 10:16










  • Welcome @Abhi. Upvote if you liked it.
    – Viren Malhan
    Nov 13 '18 at 10:19
















override methods should be written in uitableviewcell?
– Abhi
Nov 13 '18 at 10:10




override methods should be written in uitableviewcell?
– Abhi
Nov 13 '18 at 10:10












Yes. you have to override it in your custom cell.
– Viren Malhan
Nov 13 '18 at 10:13






Yes. you have to override it in your custom cell.
– Viren Malhan
Nov 13 '18 at 10:13














thank you... I got the solution. It's working
– Abhi
Nov 13 '18 at 10:16




thank you... I got the solution. It's working
– Abhi
Nov 13 '18 at 10:16












Welcome @Abhi. Upvote if you liked it.
– Viren Malhan
Nov 13 '18 at 10:19




Welcome @Abhi. Upvote if you liked it.
– Viren Malhan
Nov 13 '18 at 10:19


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53278002%2fmanage-tableview-cell-after-reloading-cell-from-tableview-data-in-textfield-is%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python