A p-n nanocomposite based on TiO2 nanotubes (NTs) and NiO nanoparticles (NPs) was designed and optimized in this study to improve the photocatalytic performance of methylene blue (MB). The hydrothermal technique has been used to produce TiO2/NiO nanocomposites with different NiO NPs weight ratios; 1TiO2:1NiO, 1TiO2:2NiO, and 1TiO2:3NiO. The crystal phase, chemical composition, optical properties, and morphology of TiO2/NiO were explored by various techniques. TiO2 NTs have a monoclinic structure, while NiO NPs have a cubic structure, according to the structural study. The bandgap of TiO2 NTs was reduced from 3.54 eV to 2.69 eV after controlling the NiO NPs weight ratio. The TiO2/2NiO nanocomposite showed the best photodegradation efficiency. Within 45 min of solar light irradiation, the efficiency of MB dye degradation using TiO2/2NiO hits 99.5% versus 73% using pure TiO2 NTs. Furthermore, the catalytic photodegradation efficiency did not deteriorate significantly even after five reusability cycles, intimating the high stability of the TiO2/2NiO nanocomposite. This suggests that the loading of NiO NPs into TiO2 NTs lowers the recombination of photo-produced electron/hole pairs and enlarged solar spectral response range, which results in improved photocatalytic activity. The mechanism of charge transfer in the TiO2/NiO and kinetic models were discussed for the photodegradation of MB.